<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<!-- 在普通的標簽模板中,推薦使用短橫線的方式使用組件 -->
<hello-world></hello-world>
<p>---------------這里是分割線---------------</p>
<button-counter></button-counter>
</div>
<script type="text/javascript" src="./vue.js"></script>
<script type="text/javascript">
/*
組件命名方式: 短橫線、駝峰
Vue.component('my-component', {})
Vue.component('MyComponent', {})
如果使用駝峰式命名組件,那么在使用組件的時候,只能在字符串模板中用駝峰的方式使用組件,但是在普通的標簽模板中,必須使用短橫線的方式使用組件
*/
Vue.component('HelloWorld', {
template: '<div>{{msg}} --- 哈哈哈</div>',
data() {
return {
msg: 'HelloWorld'
}
}
});
Vue.component('button-counter', {
template: `
<div>
<button @click="handle">點擊了{{count}}次</button>
<button>測試123</button>
<!-- 在字符串模板中用駝峰的方式使用組件 -->
<h3>下面是在字符串模板中用駝峰的方式使用組件</h3>
<HelloWorld></HelloWorld>
</div>
`,
data() {
return {
count: 0
}
},
methods: {
handle: function () {
this.count += 2;
}
}
})
var vm = new Vue({
el: '#app',
data: {
}
});
</script>
</body>
</html>