问题描述
明明注册了组件,写了模板,但是在html中就是不能用,打haha后面也没提示,就算自己打全了,也不管用,就跟没注册一样。
ps:代码没打完,后面还没写,不过不影响
问题出现的环境背景及自己尝试过哪些方法
总是有这个问题
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
<body>
<div id="app">
<p>总数:{{total}}</p>
<haha>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
Vue.component('hahaha',{
template:'<div><button @click='jia'>+1</button></div>',
data:{
return{
count:0
}
},
methods:{
jia:function(){
this.count++;
}
}
})
</script>
</body>
按F12,查看控制台错误,这种没反应的肯定在后台有报错
上面有两点我觉得不合适的地方
1、组件名字写全 <hahaha />
2、template:'<div><button @click='jia'>+1</button></div>',外层双引号, click写单引号
其他地方没看出问题