Classic mode for store/is deprecated and will be removed in Nuxt 3.
4836 ワード
Classic mode for store/is deprecated and will be removed in Nuxt 3.ソリューション問題の原因 ソリューション index.js その他のmoduledのjs 問題の原因
Classic mode for store/is deprecated and will be removed in Nuxt 3. 古典的なVuexモードの書き方はNUXT 2.4以降のバージョンは推奨されませんが、NUXT 3以降はこの書き方で直接削除します
ソリューション
公式文書も詳しく書かれています.公式ドキュメント
公式の推薦での書き方は簡単で効率的です
まず元のバージョンと一致し、プロジェクトにstoreディレクトリnuxtがあるとvueインスタンスにvuexが自動的にマウントされます.つまり、vueには必要ありません.use(vuex)とか
書き方を書き直す
まず各モジュールのstateを関数としてエクスポートします!残りの操作と変数は定数またはオブジェクトとしてエクスポートされます.
じょうふごう
index.js
その他のmoduledのjs
Classic mode for store/is deprecated and will be removed in Nuxt 3. 古典的なVuexモードの書き方はNUXT 2.4以降のバージョンは推奨されませんが、NUXT 3以降はこの書き方で直接削除します
ソリューション
公式文書も詳しく書かれています.公式ドキュメント
公式の推薦での書き方は簡単で効率的です
まず元のバージョンと一致し、プロジェクトにstoreディレクトリnuxtがあるとvueインスタンスにvuexが自動的にマウントされます.つまり、vueには必要ありません.use(vuex)とか
書き方を書き直す
まず各モジュールのstateを関数としてエクスポートします!残りの操作と変数は定数またはオブジェクトとしてエクスポートされます.
じょうふごう
index.js
export const actions = {
async nuxtServerInit({commit}, {req, app}) {
const {status,data:{province,city}} = await app.$axios.get('/geo/getPosition')
commit('geo/setPosition', status===200? {city,province} : {city:'',province:''} )
}
}
その他のmoduledのjs
export const state = () => ({
position: {}
})
export const mutations = {
setPosition(state,val) {
state.position = val
}
}
export const actions = {
setPosition({commit}, position) {
commit('setPosition',position)
}
}