当前位置:网站首页 > Vue.js开发 > 正文

Nuxt.js报错:Classic mode for store/ is deprecated and will be removed in Nuxt 3

将Nuxt.js升级到最新版的2.4.0时,终端提示警告:

Classic mode for store/ is deprecated and will be removed in Nuxt3

在Nuxt.js的源码中,其中有一段代码如下:

// If store is an exported method = classic mode (deprecated) if (typeof store === 'function') { const log = (process.server ? require('consola') : console) return log.warn('Classic mode for store/ is deprecated and will be removed in Nuxt 3.') }

从代码中我们可以看出,它对store做了一个是否方法的判断,如果我们export的是一个方法就会出现本文中的警告信息。 如下是出现警告信息的写法(文件路径:store/index.js):

import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const state = { token:null, } const getters = { getToken(state){ return state.token }, } const mutations = { setToken(state, token) { state.token = token }, } export const actions = { //TODO ajax here } const store = () => { return new Vuex.Store({ state, getters, mutations, actions }) } export default store

改成如下的写法就可以了(文件路径:store/index.js):

export const state = () => ({ token:null, }) export const getters = { getToken(state){ return state.token }, } export const mutations = { setToken(state, token) { state.token = token }, } export const actions = { //TODO ajax here } 

Classic mode for store/ is deprecated and will be removed in Nuxt 3.解决方案

到此这篇Nuxt.js报错:Classic mode for store/ is deprecated and will be removed in Nuxt 3的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • Nuxt.js中安装使用插件【ElementUI,axios,scss】2024-11-30 10:54:04
  • VUE 爬坑之旅 -- 引入静态资源的正确方式2024-11-30 10:54:04
  • VUE好用地址2024-11-30 10:54:04
  • vue实现可拖拽可缩放功能2024-11-30 10:54:04
  • VUE指定的页面缓存2024-11-30 10:54:04
  • vue动态路由:路由参数改变,视图不更新问题的解决2024-11-30 10:54:04
  • VUE控制台报错: [vue-router] Duplicate named routes definition: { name: "NotFound", path: "*" }2024-11-30 10:54:04
  • VUE实现延时请求接口2024-11-30 10:54:04
  • VUE报错because it violates the following Content Security Policy directive2024-11-30 10:54:04
  • vue路由切换报错message: "Navigating to current location (XXX) is not allowed"的解决方案2024-11-30 10:54:04
  • 全屏图片