Vue.js: 更新子 json 数据库中的数据格式

Vue.js: update child json data format in db

我只需要更新 commented_type 列中的评级值。在 Laravel 上,我使用 commented_type>rating。但是我不知道怎么办 vue.js.

JSON 列如下:

commented_type
 {"type": "review", "rating": 5}



updateReview: function () {
    var reviewData = {
        id:584,
        commented_type>rating:'4',//It does not work like that
    };
    this.$http.patch('/review/584',reviewData).then((response) => {

        console.log(response.data);

    }, (response) => {
        // error callback
        console.log('error response review update')
    });
},

您的 JSON 当前是字符串形式吗?如果您需要获取对象,请尝试使用 JavaScript 的 JSON.parse()

否则,听起来你只是在问 JS 中的 property accessors。试试这个:

commented_type['rating']