nuxt

作者: 曹锦花 | 来源:发表于2020-01-07 19:10 被阅读0次

https://zh.nuxtjs.org/guide/
Nuxt.js 是一个基于 Vue.js 的通用应用框架。

nuxt安装

npx create-nuxt-app <项目名>

router

Nuxt.js 会依据 pages 目录中的所有 *.vue 文件生成应用的路由配置。(.nuxt/router.js)
要在页面之间使用路由,使用<nuxt-link> 标签。

<template>
  <nuxt-link to="/">首页</nuxt-link>
</template>

pages目录中的同名文件夹生成同名.vue文件的嵌套路由
.vue文件使用<nuxt-child />来显示
_id.vue会生成/:id

在plugins/router.js中 可设置路由守卫beforeEach
设置后需在nuxt.config.js中添加router

  plugins: [
    '@/plugins/element-ui',
    '@/plugins/router'
  ],

layouts/default.vue 布局页

vuex

应用根目录下如果存在store目录,nuxt.js将启用vuex状态树
定义各状态树时具名导出state,mutations,getters,actions即可

跨域只出现在浏览器 如果请求在服务器端 则不会出现跨域

相关文章

网友评论

      本文标题:nuxt

      本文链接:https://www.haomeiwen.com/subject/vboractx.html