您的位置:首页 > 移动开发

[Nuxt] Setup a "Hello World" Server-Rendered Vue.js Application with the Vue-CLI and Nuxt

2017-07-24 15:33 676 查看
Install:

npm install -g vue-cli


Init project:

vue init nuxt/starter .


Run:

npm run dev


Create a index.js file inside store folder:

import Vuex from 'vuex'

const store = () => new Vuex.Store({
state: {
counter: 0
}
})

export default store


Display the counter inside pages/index.vue:

<template>
<div>
Counter: {{counter}}
</div>
</template>

<script>
import { mapState } from 'vuex'

export default {
computed: mapState({
counter: (state) => state.counter
})
}
</script>


mapState: return a state tree object.

We can also write:

computed: {
...mapState({
counter: (state) => state.counter
})
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐