0
を変異さ:私は私のプロジェクトの次のセットアップ持ってVueのプロップ(Vue2 + Laravel)
window.school = {
"id": 1,
"users": [
{
"id": 0,
"name": "Adam Carter",
"work": "Unilogic",
"email": "[email protected]",
"dob": "1978",
"address": "83 Warner Street",
"city": "Boston",
"optedin": true
},
{
"id": 1,
"name": "Leanne Brier",
"work": "Connic",
"email": "[email protected]",
"dob": "13/05/1987",
"address": "9 Coleman Avenue",
"city": "Toronto",
"optedin": false
}
],
"images": [
"img0.png",
"img1.png",
"img2.png"
],
"coordinates": {
"x": 35.12,
"y": -21.49
},
"price": "$59,395"
}
const app = new Vue({
router,
el: '#app',
data: {
school: school,
}
});
そして、私のVUEの構成要素の一つはSchool.vue
として<template>
<div>
<input type="button" value="Update school data" v-on:click="update()">
</div>
</template>
<script>
export default {
props:[
'school',
],
methods: {
update: function() {
let url = `/api/v1/school/${this.school.id}/update`;
this.axios.get(url, this.decisions)
.then((res) => {
// WARNING IS THROWN IN HERE
this.school = res.data.school;
})
.catch((error) => {
console.log(error);
});
}
},
}
</script>
あるしかし、私は取得warning: Avoid mutating a prop directly
質問:アプリの「学校」情報をVueコンポーネントから更新するにはどうすればよいですか?私はVueにあまり精通していないので、反パターンなどに従っているかどうかはわかりません。