morevue.htmljavascript
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <title>Insert title here</title> </head> <body> <h1>多個vue實例對象</h1> <div id="app-vue-one"> {{name}} <p>{{getname}}</p> </div> <div id="app-vue-tow"> {{name}} <p>{{getname}}</p> <button v-on:click="tochangeone">改變one對象的名稱</button> </div> </body> <script src="morevue.js"></script> </html>
morevue.jshtml
const one=new Vue({ el:"#app-vue-one", data(){ return{ name:"im one" } }, methods:{ }, computed:{ getname(){ return "get name="+this.name; } } }); const tow=new Vue({ el:"#app-vue-tow", data(){ return{ name:"im tow" } }, methods:{ tochangeone(){ one.name="im one add tow" } }, computed:{ getname(){ return "get name="+this.name; } } });
頁面效果vue
點擊按鈕以後java