2
嗯,我試圖改變Vue的「變量」的值,但是當我按一下按鈕,他們在控制檯拋出一個消息:而是使用基於道具值的數據或計算屬性。 Vue公司JS
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "menuOpen"
我不知道如何解決這個問題...
我file.vue:
<template>
<button v-on:click="changeValue()">ALTERAR</button>
</template>
<script>
export default {
name: 'layout',
props: [ 'menuOpen' ],
methods: {
changeValue: function() {
this.menuOpen = !this.menuOpen
}
},
}
</script>
任何一個可以幫助我嗎?謝謝
我以爲我這樣做了,我看到很多教程,並沒有得到!多謝,夥計。 –
另外,從v2.3開始,您可以使用'.sync'修飾符:https://vuejs.org/v2/guide/components.html#sync-Modifier – giannoug