一、组件
<template>
<button @click="handleClick">{{city}}</button>
</template>
<script setup>
import { computed } from '@vue/runtime-core';
import {useStore} from 'vuex'
const store = useStore();
let city = computed(()=>{
return store.state.city
})
function handleClick(){
store.commit("changeCity","苏州")
}
</script>
二、vuex
import { createStore } from 'vuex'
export default createStore({
state: {
city:"武汉"
},
mutations: {
changeCity(state,city){
state.city = city
}
}
})