<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