nuxt.js

Nuxt.js学习(九) --- 静态应用部署、单页应用程序部署

喜欢而已 提交于 2020-01-07 18:12:18
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> [TOC] 一、静态应用部署 官方文档: Nuxt.js 可依据路由配置将应用静态化,使得我们可以将应用部署至任何一个静态站点主机服务商。 可利用下面的命令生成应用的静态目录和文件: npm run generate 这个命令会创建一个 dist 文件夹,所有静态化后的资源文件均在其中。 如果你的项目需要用到 动态路由 ,请移步 generate配置API 了解如何让 Nuxt.js 生成此类动态路由的静态文件。 注意:使用 nuxt generate 静态化应用的时候, 传给 asyncData() 和 fetch() 方法的 上下文对象 不会包含 req 和 res 两个属性。 二、单页面应用程序部署 (SPA) nuxt generate 在 build/generate 时间内仍然需要SSR引擎,同时具有预渲染所有页面的优势,并具有较高的SEO优化和页面加载能力。 内容在构建时生成。例如,我们不能将它用于内容依赖于用户身份验证或实时API的应用程序(至少对于第一次加载)。 SPA应用的想法很简单! 使用时启用SPA模式 mode: 'spa' 或 --spa ,并且我们运行打包,生成在导报后自动启动,生成包含常见的meta和资源链接,但不包含页面内容。 因此,对于SPA部署,您必须执行以下操作: 将

Nuxt.js学习(八) --- 异步数据

孤街醉人 提交于 2020-01-06 20:53:22
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> [TOC] 1、异步数据 1.1、官方文档: Nuxt.js 扩展了 Vue.js,增加了一个叫 asyncData 的方法,使得我们可以在设置组件的数据之前能异步获取或处理数据。 asyncData 方法 asyncData 方法会在组件( 限于页面组件 )每次加载之前被调用。它可以在服务端或路由更新之前被调用。 在这个方法被调用的时候,第一个参数被设定为当前页面的 上下文对象 ,你可以利用 asyncData 方法来获取数据,Nuxt.js 会将 asyncData 返回的数据融合组件 data 方法返回的数据一并返回给当前组件。 注意:由于asyncData方法是在组件初始化前被调用的,所以在方法内是没有办法通过 this 来引用组件的实例对象。 Nuxt.js 提供了几种不同的方法来使用 asyncData 方法,你可以选择自己熟悉的一种来用: 返回一个 Promise , nuxt.js会等待该 Promise 被解析之后才会设置组件的数据,从而渲染组件. 使用 async 或 await ( 了解更多 ) 我们使用[axios]重构HTTP请求,我们强烈建议您使用[axios模块]用于您的Nuxt项目中。 如果您的项目中直接使用了 node_modules 中的 axios ,并且使用 axios

Hiding a pargraph using v-if through vuex but containing that in a specific tab

我的未来我决定 提交于 2020-01-06 05:27:06
问题 I have an array in My store which i am looping through to get a list which will be their own pages and share a same paragraph. I have a button which hides the paragraph. How do i make it so that it hides only on the first page and not on the other pages? So the way it should work is that if hide the paragraph in the Apple page, it should still appear on the other four pages.Or for the matter, if i hide the paragraph on any of the pages, it should not affect on any other page. Thank You import

How to set InnerText with directive in SSR Vue/Nuxt

安稳与你 提交于 2020-01-06 04:46:15
问题 I want to port my vue directive to also render server side. client side: mydirective(el,binding,vnode){ el.innerText = vnode.context.$data.points } What i have working so far in nuxt.config.js: render: { bundleRenderer: { directives: { mydirective(node, binding){ var points = node.context.$data.points //works node.data.style = [{backgroundColor: 'green'}] //works node.data.innerText = points //NOT working node.data.textContent = points //NOT working } I cant find the element reference. i used

npm build (nuxt build) does not create dist folder in amplify(aws codebuild) using nuxt spa mode

眉间皱痕 提交于 2020-01-06 03:52:27
问题 I want to create dist folder, after running 'npm build'(nuxt build) in amplify. I run npm build in my local(mac) , then dist folder is created. I run 'ls -a' after 'npm build' , then dist folder does not exist in amplify. > nuxt build 2019-08-20T01:49:08.598Z [INFO]: # Executing command: ls -a 2019-08-20T01:49:08.602Z [INFO]: . .. amplify.sh amplify.yml assets components .editorconfig .eslintrc.js .git .gitignore layouts middleware node_modules .nuxt nuxt.config.js package.json package-lock

Add a slask / at the end of every routes in Nuxt.js

我与影子孤独终老i 提交于 2020-01-06 01:17:21
问题 For a purpose of SEO i've been asked to add a slash at the end of every routes of my nuxt project. For example myapp.com/company should be myapp.com/company/ Is there a clean way to do that in Nuxt ? 回答1: ok i found the solution by writting a redirection in a middleware on serverside, so first i added to nuxt.config.js this : serverMiddleware: ["~/servermiddleware/seo.js"], then i created this file /servermiddleware/seo.js : const redirects = require('../301.json'); module.exports = function

Nuxt/Vue: How to position custom loading component

杀马特。学长 韩版系。学妹 提交于 2020-01-05 06:47:30
问题 I use nuxt and I followed this guide to make custom loading component: https://nuxtjs.org/api/configuration-loading/#use-a-custom-loading-component This does work, but the loader is in the same position as the original nuxt loader bar: You can see, I really added a very big and very simple loader with a red div. At the bottom you can see my headebar (black bar with letter «s») so everything is moved downwards. What I would like to achieve is that the loader takes the position of the page

Nuxt/Vue: How to position custom loading component

泪湿孤枕 提交于 2020-01-05 06:45:02
问题 I use nuxt and I followed this guide to make custom loading component: https://nuxtjs.org/api/configuration-loading/#use-a-custom-loading-component This does work, but the loader is in the same position as the original nuxt loader bar: You can see, I really added a very big and very simple loader with a red div. At the bottom you can see my headebar (black bar with letter «s») so everything is moved downwards. What I would like to achieve is that the loader takes the position of the page

Nuxt error in ./.nuxt/client.js | this.setDynamic is not a function

三世轮回 提交于 2020-01-05 06:16:09
问题 I can not understand what caused this error and whether it is related to my code. nuxt v1.4.2, windows 10 Can you please tell what could cause this error? 回答1: It's very strange, but after removing package vuepress , it all worked 回答2: I had this issue after updating from 1.4.2 to 2.1.0 today. It affected my static generation, not my local dev instance, but maybe this will help: to resolve it, I simply removed my .nuxt and dist directories and ran nuxt generate again. 回答3: Switched from yarn

Nuxt error in ./.nuxt/client.js | this.setDynamic is not a function

北战南征 提交于 2020-01-05 06:15:45
问题 I can not understand what caused this error and whether it is related to my code. nuxt v1.4.2, windows 10 Can you please tell what could cause this error? 回答1: It's very strange, but after removing package vuepress , it all worked 回答2: I had this issue after updating from 1.4.2 to 2.1.0 today. It affected my static generation, not my local dev instance, but maybe this will help: to resolve it, I simply removed my .nuxt and dist directories and ran nuxt generate again. 回答3: Switched from yarn