站点微信订阅号zhengjinyibu,欢迎大家搜索关注.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| var bus =new Vue(); Vue.component("myButton",{ template:"#my_input", data:function(){ return { counter:1, } }, methods:{ updateVal:function(){ bus.name= ++this.counter; bus.$emit("on-message") } }
}) var app=new Vue({ el:"#app", data:{ "name":"namehere", }, methods:{ }, mounted:function(){ var _this= this; bus.$on("on-message",function(){ _this.name=bus.name; }) } })
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@include file="/WEB-INF/webpage/common/taglibs.jspf"%> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>${title}</title> <meta name="decorator" content="single"/> <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head> <body> <div id="app"> {{name}} <div> <my-button></my-button> </div> </div>
<template id="my_input"> <div @click="updateVal">click div here</div> </template>
<script> var bus =new Vue(); Vue.component("myButton",{ template:"#my_input", data:function(){ return { counter:1, } }, methods:{ updateVal:function(){ bus.name= ++this.counter; bus.$emit("on-message") } }
}) var app=new Vue({ el:"#app", data:{ "name":"namehere", }, methods:{ }, mounted:function(){ var _this= this; bus.$on("on-message",function(){ _this.name=bus.name; }) } }) </script> </body>
</html>
|
本文内容仅作为作者个人兴趣与观点,不代表所在公司及团队的观点和决策。若有不恰当之处,请联系站长.