Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问使用vuex报错 Vue is not defined你怎解决的 #19

Open
hong-xu opened this issue Jan 8, 2019 · 5 comments
Open

请问使用vuex报错 Vue is not defined你怎解决的 #19

hong-xu opened this issue Jan 8, 2019 · 5 comments

Comments

@hong-xu
Copy link

hong-xu commented Jan 8, 2019

入口enter.js代码

const App = require('@/index.vue');
import api from '@/apis/index.js';

import store from './store';
import nInput from '@/components/n-input.vue';
const router = require('./router');

Vue.component('n-input', nInput);
Vue.use(api);

new Vue(Vue.util.extend({el: '#root', router, store}, App));
router.push('/');

store.js的代码

import Vuex from 'vuex'

import common from '@/store/common/index';
import user from '@/store/user/index';
import performance from '@/store/performance/index';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        name: '9000001'
    },
    modules: {
        common: common,
        user: user,
        performance: performance
    },
    strict: false
})

修改了configs的配置

image
image
运行npm run start 报错
image

@CarGuo
Copy link
Owner

CarGuo commented Jan 8, 2019

看下面代码,虽然项目里没有 import Vue from 'vue'\n,但是事实上编译时加了

const getEntryFileContent = (source, routerpath) => {
  let dependence = `import Vue from 'vue'\n`;
  ······
const getEntryFile = () => {
  const entryFile = path.join(vueWebTemp, config.entryFilePath)
  const routerFile = path.join(vueWebTemp, config.routerFilePath)
  const storeFile = path.join(vueWebTemp, config.storeFilePath)
  fs.outputFileSync(entryFile, getEntryFileContent(helper.root(config.entryFilePath), routerFile));
  fs.outputFileSync(routerFile, getRouterFileContent(helper.root(config.routerFilePath)));
  fs.outputFileSync(storeFile, getRouterFileContent(helper.root(config.storeFilePath)));//他
  return {
    index: entryFile
  }
}

源文件
https://github.com/CarGuo/GSYGithubAppWeex/blob/46c253b48126ac5dba14bd8e0b08a8c50824e816/src/store.js
效果文件
https://github.com/CarGuo/GSYGithubAppWeex/blob/46c253b48126ac5dba14bd8e0b08a8c50824e816/.temp/store.js

@hong-xu
Copy link
Author

hong-xu commented Jan 9, 2019

编译后的store.js是有import Vue的
image
但是项目运行的文件还是用的源文件

image

入口文件引的也是编译后的文件,还是报错我就是想不通哪里出了问题
image

@hong-xu
Copy link
Author

hong-xu commented Jan 9, 2019

直接用你项目的配置也是不行,但是你的项目是可以,感觉是人品问题

@CarGuo
Copy link
Owner

CarGuo commented Jan 9, 2019

很明显你白色图里的打包进去的js代码里没有 vue

@hong-xu
Copy link
Author

hong-xu commented Jan 9, 2019

就是没有啊就报错了,web环境下打包进去的还是store.js的源文件。并不是编译好的.temp里的store.js文件,但是删掉.temp文件夹里的store.js又会报错:没找到store.js。我是真的不知道哪里出了问题,先不纠结了,打包web运行的文件先自己手动加下import Vue 吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants