前面创建组件通过:
//创建组件构造器
const myTitle = Vue.extend({template:""});
//注册组件
Vue.component('my-title',myTitle);
语法糖写法:
Vue.component('my-title',{template:""});
我是分割线
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<!--3. 使用组件-->
<my-title></my-title>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
/*//1.创建组件构造器
const myTitle = Vue.extend({
template: `
<div>
<span>Title</span>
<span>User</span>
</div>`
});*/
//2. 直接(组件名,{template})
Vue.component('my-title',{
template:`
<div>
<span>Title</span>
<span>User</span>
</div>`
});
let app = new Vue({
el: '#app',
});
</script>
</body>
</html>
我是分割线
前台效果:
Title