我正试图以Vuex ("^2.1.3")
方式使用vuejs ("^2.1.10")
:
store.js:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
inTheaters: [
{
name: 'Resident Evil: The Final Chapter',
poster_url: 'https://blackgirlnerds.com/wp-content/uploads/2017/02/Resident-Evil-The-Final-Chapter-Final-Poster-Featured.jpg',
language: 'English',
},
{
name: 'Irada',
poster_url: 'http://filmywave.com/wp-content/uploads/2017/02/irada-movie-poster-1.jpg',
language: 'Hindi',
},
]
},
});
main.js:
import store from './store';
new Vue({
router,
components: {App},
template: '<App/>',
store,
}).$mount('#app');
一些-component.js:
<script>
export default {
name: 'movieListWrapper',
props: {
movieListType: {
type: String,
default: 'in-theateras',
},
},
computed: {
movieList() {
return this.$store.state.inTheaters;
}
},
}
</script>
我现在有两个问题:
&#34;导出&#39;默认&#39; (在&#39; ./ store&#39;中找不到导入&#39;商店&#39;
state
未定义。未捕获的TypeError:无法读取属性&#39; state&#39;未定义的
我对此很陌生,可能是我错过了一些事情所以请原谅我。我错过了什么?
答案 0 :(得分:14)
在你的store.js:
export default new Vuex.Store({
代替export const store = new Vuex.Store({
或者@dfsq说import {store} from './store';
答案 1 :(得分:1)
// state.js
export const store = new Vuex.Store({
state :{
title :"Welcome in Vuex Tutorials By SK Islam"
}
});
然后在main.js中,请以这种方式导入商店。
import {store} from "./store/state";
{store} //这很重要。