vue项目开发中,vuex里面的sotre数据改变,但视图没有及时更新的解决方法

<template>
	<div id="app">
		<button @click="clickme">点击</button>
		<span>{{countnumber}}</span>
	</div>
</template>
<script>
	export default {
		name: 'app',
		data() {
			return {
				countnumber: this.$store.state.count,
			}
		},
		methods: {
			clickme: function() {
				this.$store.commit("increment");
			}
		},
	}
</script>
<style>

解决方法如下:区别就是你直接关联到界面里面

<template>
	<div id="app">
		<button @click="clickme">点击我</button>
		<span>{{$store.state.count}}</span>
	</div>
</template

参考源博主:https://blog.csdn.net/HUSHILIN001/article/details/78042234

猜你喜欢

转载自www.cnblogs.com/star-meteor/p/12719051.html