<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../vue.js"></script>
		<script src="../vuex.js"></script>
	</head>
	<body>
		<div id="app">
			<button @click="param">传递参数</button>
			<p>{{this.$store.state.param}}</p>
		</div>
		<script>
			var store=new Vuex.Store({
				state:{param:''},
				mutations:{
					receive(state,param){
						state.param=param
					}
				},
				actions:{
					param(context){
						context.commit('receive','我是传递的参数')
					}
				}
			})
			var vm=new Vue({
				el:'#app',
				store,
				methods:{
					param(){
						this.$store.dispatch('param')
					}
				}
			})
		</script>
	</body>
</html
!DOCTYPE htmlhtml	head		meta charset=UTF-8		titletitle		script src=vuejsscript		script src=vuexjsscript	head	body		div id=app			button click=param传递参数button			pthis$storestateparamp		div		script			var

原文地址: https://www.cveoy.top/t/topic/fgen 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录