Я только начал изучать VueJs и пытаюсь связать clickEvent
и скрыть сообщение <article>
. Но это показывает следующее предупреждение -
[Vue warn]: Property or method "hideModel" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
Хотя, когда я пытаюсь встроить, как.
<button type='button' v-on:click='isInvisible=false'>X</button>
Работает нормально. Но с функцией это не работает.
index.html
<div id="root">
<message title="my-message" body="lorem ipsum sit ben"></message>
<message title="Other message" body="This is other message">
</message>
</div>
<link rel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.css" />
<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
<script src="main.js"></script>
main.js
Vue.component('message', {
props:['title', 'body'],
data(){
return {
isVisible:true
};
},
template:`<article class="message" v-show='isVisible'>
<div class="message-header">
<p>{{ title }}</p>
<button type='button' v-on:click='hideModel'>X</button>
</div>
<div class="message-body">
{{body}}
</div>
</article>`,
method:{
hideModel(){
this.isVisible=false;
}
}
})
new Vue({
el:"#root",
});