index.html
<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://unpkg.com/vue"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!--vue-app是根容器-->
<h1>初始Vue组件</h1>
<div id="vue-app-one">
<greeting></greeting>
</div>
<div id="vue-app-two">
<greeting></greeting>
</div>
<script src="app.js"></script>
</body>
</html>
app.js
Vue.component("greeting",{
template:"<p>{{name}}:大家好!!!<button v-on:click='changeName'>改名</button></p>",
data:function () {
return {
name:"Miracle"
}
},
methods:{
changeName:function () {
this.name="AAAAA"
}
}
});
new Vue({
el:"#vue-app-one",
});
new Vue({
el:"#vue-app-two",
});