官网
教程
组件作为单独.js 引入使用
文件结构如下
js
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
html 界面使用
说明: <script src="button-counter.js"></script>
引入组件
<button-counter></button-counter>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="button-counter.js"></script>
</head>
<body>
<div id="vue-app">
<div id="app">
{{ message }}
<ol>
<!-- 创建一个 todo-item 组件的实例 -->
<todo-item></todo-item>
<button-counter></button-counter>
</ol>
</div>
</div>
<script>
Vue.component('todo-item', {
template: '<li>这是个待办项</li>'
})
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
</script>
</body>
</html>
每次都要登录好麻烦 准备转移了