1
我想以这种方式来使用Vuex ("^2.1.3")
与vuejs ("^2.1.10")
项目:Vuex商店状态不定
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');
一些组分.js:
<script>
export default {
name: 'movieListWrapper',
props: {
movieListType: {
type: String,
default: 'in-theateras',
},
},
computed: {
movieList() {
return this.$store.state.inTheaters;
}
},
}
</script>
我现在有两个问题:
- 首先是我在我的控制台得到一个警告
"export 'default' (imported as 'store') was not found in './store'
- 另一个问题是,
state
没有定义。
Uncaught TypeError: Cannot read property 'state' of undefined
我很新的这一点,可能是我错过了一些东西,所以请原谅我。我错过了什么?
尝试'出口默认新Vuex.Store({',而不是'出口常量店=新Vuex.Store({''你的store.js中可能是?' – Traxo
或'从'./store';'0123'进口{store};' – dfsq
是的!我尝试了两种方式,都是解决问题的答案。 – Kakar