如何獲取到vuex中data的值
uni-app中內置了 vuex
所以可以直接去使用哈。
在項目的跟目錄下 創建文件夾store
在store目錄下創建index.js
index.js目錄如下
import Vue from 'vue'
import Vuex from "vuex"
Vue.use(Vuex)
export default new Vuex.Store({
state:{
testArr:[
{id:1,name:"紀念日"}
],
city:"四川省"
},
// 同步更改值
mutations:{
},
//異步
actions:{
getCity(){
console.log()
}
}
})
在main.js中引入vuex,並且掛載到原型上
import Vue from 'vue'
import App from './App'
// 引入store
import store from "./store"
Vue.config.productionTip = false
//將state掛載到原型上
Vue.prototype.$store=store;
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
在index.vue這個頁面中去獲取vuex中state中的值
onLoad(){
console.log("12", this.$store.state)
}

當我在使用vuex的使用,遇見的一些小問題。
比如說。
在將vuex引入進來的時候,
我想獲取它里面的值,始終打印不出來。
因為我的頁面寫錯了。
我寫console.log()一個固定的值,都沒有打印出來。
這個時候,我才發現,頁面寫錯了。
這個跟vue是一樣的哈
