码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-07-24 16:22:46      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:write   ted   start   setup   tree   put   server   ati   display   

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
      })
    }

 

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

标签:write   ted   start   setup   tree   put   server   ati   display   

原文地址:http://www.cnblogs.com/Answer1215/p/7229195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!