<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.js"></script>
<script src="vuex.js"></script>
</head>
<body>
<div id="box">
<button @click="add">{{$store.state.count}}</button>
<veb></veb>
</div>
</body>
<script>
//其他组件的访问
// Vue.component("veb",{
// template:`<button>{{$store.state.count}}</button>`,
// })
Vue.component("veb",{
template:`<button>{{count}}</button>`,
computed:{
count:function(){
return this.$store.state.count //假设{{name}},在里面的钩子函数都是通过this去访问的
}
}
})
var box=new Vue({
el:"#box",
data:{
},
store:new Vuex.Store({
state:{
count:0
},
mutations:{
add:function(state){
state.count++
}
}
}),
methods:{
add:function(){
this.$store.commit("add")
}
}
})
</script>
</html>
其他组件调用
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 原文链接 import pythoncom class PythonUtilities: _reg_clsctx_...
- 问题:父组件中有两个tab标签,每个tab下控制各自的子组件,并且每个tab下面的数据可相互转换。 如上图所示,待...