Vue组件注册注册注意事项下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>组件注册注意事项</title>
</head>
<body>
<div id="app">
<button-counter></button-counter>
<hello-world></hello-world>
</div>
</body>
<script src="../js/vue.js"></script>
<script>
/*
组件注册注意事项
如果使用驼峰式命名组件,要么使用组件的时候,只能在字符串模板中使用驼峰的方式使用组件,但是在
普通的标签模板中,必须使用短横线的方式使用组件
*/
Vue.component('HelloWorld', {
data: function () {
return {
msg: "HelloWorld"
}
},
template: '<div>{{msg}}</div>'
});
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: `
<div>
<button @click="handle">点击了{{count}}次</button>
<button>测试123</button>
<HelloWorld></HelloWorld>
<hello-world></hello-world>
</div>
`,
methods: {
handle: function () {
this.count += 2;
}
}
})
var vm = new Vue({
el: '#app',
data: {
}
});
</script>
</html>
道阻且长,行则将至

浙公网安备 33010602011771号