【问题标题】:export 'default' (imported as 'Vue') was not found in 'vue在“vue”中找不到导出“默认”(导入为“Vue”)
【发布时间】:2021-04-26 05:34:43
【问题描述】:

我正在尝试获取后端的 url,但在导入时出现错误,不清楚如何修复它。 ./src/store/index.js 中的警告

“在'vue'中找不到导出'default'(导入为'Vue')

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        backendUrl: "http://127.0.0.1:8000/api/v1"
    },
    mutations: {},
    actions: {},
    modules: {},
    getters: {
        getServerUrl: state => {
            return state.backendUrl
        }
    }
})

export default store

工作version:

import { createStore } from "vuex";

const store = createStore({
    state: {
        backendUrl: "http://127.0.0.1:8000/api/v1"
    },
    mutations: {},
    actions: {},
    modules: {},
    getters: {
        getServerUrl: state => {
            return state.backendUrl
        }
    }
})

export default store

【问题讨论】:

  • 您正在使用不支持 Vue 3 的 vuex 3;我建议使用vue-cli为vue 3生成一个项目
  • Boussadjra Brahim,我使用此代码并出现此错误:未找到此相关模块:* ./App.vue in ./src/store/index.js 尽管路径正确 xD
  • 请分享您的main.jsApp.vue 并存储内容

标签: vue.js vuex


【解决方案1】:

如果您使用的是 vue-cli,我发现解决方案是修改 vue.config.js 以包含 devServer 属性。见Vue CLI documentation

  module.exports = {
  devServer: {
    disableHostCheck: true,
    proxy: {
      '/api-ezbook': {
        target: 'http://localhost:80',        
        ws: false
      }
    },
    public: 'http://localhost:8080'
  }
  //  use to deploy
  publicPath: '/'
  //  use to deploy to live server
  //  publicPath: '/location/on/server'
  //  in production:
  //  publicPath: '/'
}

【讨论】:

    猜你喜欢
    • 2021-12-16
    • 2020-12-25
    • 2021-01-10
    • 2021-01-10
    • 2021-07-08
    • 2021-10-25
    • 2021-03-04
    • 2018-07-21
    相关资源
    最近更新 更多