1、组件创建—有3中方法
extend()
< template id=’’>
< script type=‘text/x-template’ id=’’>
- A、调用Vue.extend(),创建名为haha的组件,template定义模板的标签,模板的内容需写在该标签下
<body>
<div id="app">
<haha></haha>
<haha></haha>
</div>
</body>
<script>
// 创建组件有三种方式
// 1、组件创建—有3中方法,
// extend()
// < template id=’’>
// < script type=‘text/x-template’ id=’’>
var haha = Vue.extend({
template:"<div>我是一个组件</div>",
})
var vm = new Vue({
el:"#app",
// 可以直接使用<haha/>了
components:{
"haha":haha
}
})
</script>
- B、标签创建,需要加上id属性
<body>
<div id="app">
&l