Mutating warn
HTML
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div>
<div id="app">
<h1>{{appText}} </h1>
<string-bar :inner-text="appText" :on-text-change="onTextChange"></string-bar>
</div>
</div>
<script>
Vue.component('string-bar', {
props: ['innerText', 'onTextChange'],
//Нет реактивного состояния для value, нет v-model
data: function() {return {
//text: this.innerText,
someOtherState: 'some value'
}},
methods: {
onEdit: function(evt) {
if (this.onTextChange) {
this.onTextChange(evt.target.value);
}
}
},
template: '<input type="text" :value="innerText" @keyup="onTextChange">'
});
var app = new Vue({
el: '#app',
data: {
appText: 'some text'
},
methods: {
onTextChange: function(evt) {
this.appText = evt.target.value;
}
}
});
</script>
</body>
</html>