// 项目结构
├── index.html
├── button-success.js
└── app.js
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>组件</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
</head>
<body>
<div id="app">
<button-success></button-success>
<button-success></button-success>
<button-success></button-success>
<button-success></button-success>
<button-success></button-success>
</div>
<script src="./app.js" type="module"></script>
<script src="https://vuejs.org/js/vue.js"></script>
</body>
</html>
button-success.js
var buttonSuccess = {
template: '<div>\
<button class="btn btn-success" @click="count++">成功 {{count}}</button>\
</div>',
data: function () {
return {
count: 0
}
},
methods: {
access: function () {
alert('成功');
}
}
};
export {buttonSuccess};
app.js
import {buttonSuccess} from './button-success.js';
var app = new Vue({
el: '#app',
components: {
'button-success': buttonSuccess
}
})
注意
不要漏掉了.js