欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nuxt的路由動畫效果案例

 更新時間:2020年11月06日 15:04:18   作者:UIEngineer  
這篇文章主要介紹了Nuxt的路由動畫效果案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

路由的動畫效果,也叫作頁面的更換效果。Nuxt.js提動兩種方法為路由提動動畫效果,一種是全局的,一種是針對單獨頁面制作。

全局路由動畫

全局動畫默認使用page進行設(shè)置,例如現(xiàn)在我們?yōu)槊總€頁面都設(shè)置一個進入和退出時的漸隱漸現(xiàn)的效果。我們可以先在根目錄的assets/css下建立一個main.css文件。

/assets/css/main.css

.page-enter-active,.page-leave-active{
 transition: opacity 2s;
}
.page-enter,.page-leave-active{
 opacity: 0;
}

然后在nuxt.config.js里加入一個全局的css文件就可以了。

module.exports = {
 /*
 ** Headers of the page
 */
 head: {
 title: 'delnuxt',
 meta: [
  { charset: 'utf-8' },
  { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  { hid: 'description', name: 'description', content: 'Nuxt.js project' }
 ],
 link: [
  { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
 ],
 },
 css:['~assets/css/normailze.css','~assets/css/main.css'],
 /*
 ** Customize the progress bar color
 */
 loading: { color: '#3B8070' },
 /*
 ** Build configuration
 */
 build: {
 /*
 ** Run ESLint on save
 */
 extend (config, { isDev, isClient }) {
  if (isDev && isClient) {
  config.module.rules.push({
   enforce: 'pre',
   test: /\.(js|vue)$/,
   loader: 'eslint-loader',
   exclude: /(node_modules)/
  })
  }
 }
 }
}

這時候在頁面切換的時候就會有2秒鐘的動畫效果了,但是你會發(fā)現(xiàn)一些頁面時沒有效果,這是因為你沒有使用<nuxt-link>組件來制作跳轉(zhuǎn)鏈接。你需要進更改。

比如改成如下:

<nuxt-link :to="{name:'news',params:{newsId:3306}}">NEWS</nuxt-link>

改過之后你就會看到有動畫效果了。

單獨設(shè)置頁面動效

想給一個頁面單獨設(shè)置特殊的效果時,我們只要在css里改變默認的page,然后在頁面組件的配置中加入transition字段即可。例如,我們想給about頁面加入一個字體放大然后縮小的效果,其它頁面沒有這個效果。

在全局樣式assets/main.css中添加以下內(nèi)容。

.test-enter-active,.test-leave-active{
 transition: all 2s;
 font-size: 12px;
}
.test-enter,.test-leave-active{
 opacity: 0;
 font-size: 40px;
}

然后在about/index.vue組件中設(shè)置

<script>
export default {
 transition:'test'
}
</script>

補充知識:vue-ssr框架nuxt填坑

Nuxt.js 1.0.0 初始化與依賴包安裝

vue init nuxt/started

npm install

npm run dev

npm run dev 報錯

> nuxt-temp@1.0.0 dev E:\MaYunProject\nuxt-temp
> nuxt

E:\MaYunProject\nuxt-temp\node_modules\nuxt\dist\nuxt.js:79
async function promiseFinally(fn, finalFn) {
  ^^^^^^^^

SyntaxError: Unexpected token function
 at createScript (vm.js:56:10)
 at Object.runInThisContext (vm.js:97:10)
 at Module._compile (module.js:542:28)
 at Object.Module._extensions..js (module.js:579:10)
 at Module.load (module.js:487:32)
 at tryModuleLoad (module.js:446:12)
 at Function.Module._load (module.js:438:3)
 at Module.require (module.js:497:17)
 at require (internal/module.js:20:19)
 at Object.<anonymous> (E:\MaYunProject\nuxt-temp\node_modules\nuxt\index.js:17:20)

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "G:\\node\\node.exe" "G:\\node\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! nuxt-temp@1.0.0 dev: `nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt-temp@1.0.0 dev script 'nuxt'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the nuxt-temp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!  nuxt
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!  npm bugs nuxt-temp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!  npm owner ls nuxt-temp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!  E:\MaYunProject\nuxt-temp\npm-debug.log

解決錯誤

將node 升級到 node8.12.0

升級到nuxt-edge Nuxt.js 2.0

1、運行 npm run dev報錯

  ERROR Failed to compile with 1 errors
  Module build failed (from ./node_modules/eslint-loader/index.js):
  TypeError: Cannot read property 'eslint' of undefined
   at Object.module.exports (.../node_modules/eslint-loader/index.js:148:18)

  You may use special comments to disable some warnings.
  Use // eslint-disable-next-line to ignore the next line.
  Use /* eslint-disable */ to ignore all warnings in a file.

2、修正錯誤:編輯nuxt.conf.js文件并將其更改為

  - module.exports = {
  + export default {
   // ...
   build: {
    /*
    ** Run ESLint on save
    */
   - extend (config, { isDev, isClient }) {
   -  if (isDev && isClient) {
   + extend (config, { isDev }) {
   +  if (isDev && process.client) {
     config.module.rules.push({
     enforce: 'pre',
     test: /\.(js|vue)$/,
     loader: 'eslint-loader',
     exclude: /(node_modules)/
     })
    }
    }
   }
  }

3、 重啟服務(wù),打開瀏覽器并訪問:http://localhost:3000/。

以上這篇Nuxt的路由動畫效果案例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 使用Vue構(gòu)建可重用的分頁組件

    使用Vue構(gòu)建可重用的分頁組件

    分頁組件在web項目中是十分常見的組件,讓我們使用Vue構(gòu)建可重用的分頁組件,關(guān)于基本結(jié)構(gòu)和相關(guān)事件監(jiān)聽大家參考下本文
    2018-03-03
  • vue elementui table編輯表單時彈框增加編輯明細數(shù)據(jù)的實現(xiàn)

    vue elementui table編輯表單時彈框增加編輯明細數(shù)據(jù)的實現(xiàn)

    在Vue項目中,通過使用Element UI框架實現(xiàn)表單及其明細數(shù)據(jù)的新增和編輯操作,主要通過彈窗形式進行明細數(shù)據(jù)的增加和編輯,有效提升用戶交互體驗,本文詳細介紹了相關(guān)實現(xiàn)方法和代碼,適合需要在Vue項目中處理復(fù)雜表單交互的開發(fā)者參考
    2024-10-10
  • 詳解為什么Vue中不要用index作為key(diff算法)

    詳解為什么Vue中不要用index作為key(diff算法)

    這篇文章主要介紹了詳解為什么Vue中不要用index作為key(diff算法),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • vue.js使用3DES加密的方法示例

    vue.js使用3DES加密的方法示例

    這篇文章主要介紹了vue.js使用3DES加密的方法,結(jié)合實例形式分析了vue.js使用3DES加密的具體操作步驟與使用技巧,并提供了CryptoJS-v3.1.2的本地下載,需要的朋友可以參考下
    2018-05-05
  • vue2.0 watch里面的 deep和immediate用法說明

    vue2.0 watch里面的 deep和immediate用法說明

    這篇文章主要介紹了vue2.0 watch里面的 deep和immediate用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • 通過html文件來使用Vue的單文件組件形式詳解

    通過html文件來使用Vue的單文件組件形式詳解

    這篇文章主要介紹了通過html文件來使用Vue的單文件組件形式詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-05-05
  • vue項目實現(xiàn)局部全屏完整代碼

    vue項目實現(xiàn)局部全屏完整代碼

    最近需要做一個全屏功能,所以這里給大家總結(jié)下,這篇文章主要給大家介紹了關(guān)于vue項目實現(xiàn)局部全屏的相關(guān)資料,需要的朋友可以參考下
    2023-09-09
  • vue通過watch對input做字?jǐn)?shù)限定的方法

    vue通過watch對input做字?jǐn)?shù)限定的方法

    本篇文章主要介紹了vue通過watch對input做字?jǐn)?shù)限定的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • element表格行列的動態(tài)合并示例詳解

    element表格行列的動態(tài)合并示例詳解

    這篇文章主要為大家介紹了element表格行列的動態(tài)合并示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • 淺談vue中使用圖片懶加載vue-lazyload插件詳細指南

    淺談vue中使用圖片懶加載vue-lazyload插件詳細指南

    本篇文章主要介紹了淺談vue中使用圖片懶加載vue-lazyload插件詳細指南,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-10-10

最新評論