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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Nuxt] Setup a "Hello World" Server-Rendered Vue.js Application with the Vue-CLI and Nuxt(相关的知识,希望对你有一定的参考价值。

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(的主要内容,如果未能解决你的问题,请参考以下文章

如何在组合 API 的 setup() 中使用 $axios Nuxt 模块?

nuxt项目打包部署

Nuxt.js 多线程生成命令

使用 Nuxt/Vue.js 划桨

Nuxt.js 中“$axios”的类型是啥?

将 Node.js 页面部署到 AWS Elastic Beanstalk 后出现“hell.php”错误和“502 Bad Gateway”错误