中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

可以做測試的網(wǎng)站網(wǎng)絡(luò)營銷策劃與創(chuàng)意

可以做測試的網(wǎng)站,網(wǎng)絡(luò)營銷策劃與創(chuàng)意,珠海市建設(shè)工程造價協(xié)會網(wǎng)站,靜態(tài)網(wǎng)站入侵教程目錄 一、自動引入組件 1、語法 2、使用 2.1、在compoents文件下隨便創(chuàng)建index.js文件 2.2、mian.js引入該js 二、自動生成路由 1、示例: 2、使用 2.1、在router文件下隨便創(chuàng)建autoRouter.js文件 2.2、在router文件下index.js文件中引入autoRouter.js文件…

目錄

一、自動引入組件

1、語法

2、使用

2.1、在compoents文件下隨便創(chuàng)建index.js文件

2.2、mian.js引入該js

二、自動生成路由

1、示例:

2、使用

2.1、在router文件下隨便創(chuàng)建autoRouter.js文件

2.2、在router文件下index.js文件中引入autoRouter.js文件

三、總結(jié)


一、自動引入組件

我們項目開發(fā)中,經(jīng)常需要import或者export各種模塊,那么有沒有什么辦法可以簡化這種引入或者導(dǎo)出操作呢?答案是肯定的,下面就為大家介紹一下require.context

require.context?是?webpack?提供的一個 API,用于創(chuàng)建 context,即一組具有相同上下文的模塊。

使用?require.context?可以方便地加載多個模塊,并且可以靈活地控制模塊的加載順序和依賴關(guān)系。

以前我們都是通過import 方式引入組件

import A from 'components/A'
import B from 'components/B'
import C from 'components/C'
import D from 'components/D'

這樣很蛋疼,因為每加一個組件,可能都要寫這么一句,這樣有規(guī)律的事,是否可以通過自動化完成?

require.context (需要vue-cli3+的版本)

1、語法
require.context(directory, useSubdirectories, regExp)
  1. directory: 要查找的文件路徑
  2. useSubdirectories: 是否查找子目錄
  3. regExp: 要匹配文件的正則
2、使用
2.1、在compoents文件下隨便創(chuàng)建index.js文件
const requireComponent = require.context('./', true, /\.vue$/)
const install = (Vue) => {if (install.installed) returninstall.installedrequireComponent.keys().forEach(element => {const config = requireComponent(element)if (config && config.default.name) {const componentName = config.default.nameVue.component(componentName, config.default || config)}});
}if (typeof window !== 'undefined' && window.Vue) {install(window.Vue)
}export default {install
}
2.2、mian.js引入該js
import install from './compoents'
Vue.use(install)

3.3、這樣在其他頁面使用組件的時候,就不用再引用和注冊了。直接使用就可以了。

比如直接這樣使用就可以了,不用在import引入,不用components注冊了。

<template><HelloWorld></HelloWorld>
</template>

二、自動生成路由

實際開發(fā)中增加一個新的頁面可能就要重新編寫路由的問題,導(dǎo)致路由文件每次都要重新編輯,頁面較多,修改起來較為復(fù)雜。

那么有沒有什么辦法可以簡化這種引入或者導(dǎo)出操作呢?答案是肯定的,下面就為大家介紹一下require.context

以前我們都是通過import 方式引入路由

import HomeView from '../views/HomeView.vue'Vue.use(VueRouter)const routes = [{path: '/',name: 'home',component: HomeView},{path: '/about',name: 'about',component: () => import('../views/AboutView.vue')}
]
1、示例:
require.context('./test', false, /\.test\.js$/);
//(創(chuàng)建出)一個 context,其中文件來自 test 目錄,request 以 `.test.js` 結(jié)尾。
2、使用
2.1、在router文件下隨便創(chuàng)建autoRouter.js文件
let routerArr = []//查找views目錄,以.vue結(jié)尾的文件,查找子目錄
const contexts = require.context('../views/', true, /\.vue$/)contexts.keys().forEach(value => {const path = value.substr(value.indexOf('/'), value.lastIndexOf('.') - 1)const componentLocation = value.substr(value.indexOf('.') + 1, value.lastIndexOf('.') - 1)const componentName = componentLocation.substr(componentLocation.lastIndexOf('/') + 1)//添加到路由數(shù)組中routerArr.push({path: path,name: componentName,component: () => import(`@/views${componentLocation}`)})
})export default routerArr
2.2、在router文件下index.js文件中引入autoRouter.js文件
import Vue from 'vue'
import VueRouter from 'vue-router'//引入剛剛寫的autoRouter.js文件
import routerArr from './autoRouter.js'Vue.use(VueRouter)
const routes = [//這里是其他手動寫的路由
]const router = new VueRouter({mode: 'history',//這里進行路由合并routes:[...routes,...routerArr]
})export default router

完成了,后面在views里面新建頁面,就不要手動寫路由了。

三、總結(jié)

我們可以通過require.context可以自動化引入文件。
其實我們不單單局限于組件,路由內(nèi), 所有模塊文件都是通用的, 例如路由, 接口封裝模塊,都是可以使用的。

http://www.risenshineclean.com/news/63837.html

相關(guān)文章:

  • 做網(wǎng)站空間百度云和阿里云區(qū)別湘潭網(wǎng)頁設(shè)計
  • 做網(wǎng)站的服務(wù)器要什么格式高端營銷型網(wǎng)站建設(shè)
  • 專做正品 網(wǎng)站青島網(wǎng)絡(luò)科技公司排名
  • 用html5做網(wǎng)站百度經(jīng)驗網(wǎng)站怎么制作
  • 南京代做網(wǎng)站制作外鏈怎么打開
  • 上海網(wǎng)站制作顧問交換神器
  • avada做網(wǎng)站有必要買優(yōu)化大師會員嗎
  • 做啤酒行業(yè)的網(wǎng)站湖南疫情最新消息
  • 做網(wǎng)站 技術(shù)seo職位
  • 網(wǎng)站適合用angular做嗎十大免費引流平臺
  • 網(wǎng)站開發(fā)作業(yè)總結(jié)寫軟文一篇多少錢合適
  • 做外貿(mào)沒網(wǎng)站可以嗎小說推廣平臺有哪些
  • 海原縣城鄉(xiāng)建設(shè)局網(wǎng)站線上渠道推廣怎么做
  • 新手做電商怎么做推廣排名seo
  • 新聞網(wǎng)站建設(shè)源碼今日國內(nèi)新聞大事20條
  • 無錫外貿(mào)網(wǎng)站制作公司搭建一個網(wǎng)站的流程
  • 網(wǎng)站建設(shè)維護保密協(xié)議seo需要掌握哪些技術(shù)
  • 網(wǎng)站移動端做pc端的301跳轉(zhuǎn)湖南網(wǎng)站seo公司
  • 怎么做交易貓釣魚網(wǎng)站片多多可以免費看電視劇嗎
  • 貴陽做網(wǎng)站多少錢免費網(wǎng)站seo優(yōu)化
  • 設(shè)置網(wǎng)站開場動畫合肥正規(guī)的seo公司
  • wordpress 微博圖標關(guān)鍵詞優(yōu)化和seo
  • 網(wǎng)站開發(fā)原則愛站小工具圣經(jīng)
  • 多商城入住網(wǎng)站建設(shè)seo外包
  • 定陶網(wǎng)站建設(shè)怎么制作網(wǎng)頁
  • 網(wǎng)站百度知道怎么做推廣營銷軟文廣告
  • 網(wǎng)站的推廣方式組合網(wǎng)絡(luò)營銷推廣渠道有哪些
  • 深圳網(wǎng)站建設(shè) 設(shè)計科技外貿(mào)網(wǎng)站建站和推廣
  • 網(wǎng)站搭建語言網(wǎng)絡(luò)營銷成功案例介紹
  • 美橙互聯(lián)網(wǎng)站建設(shè)案例游戲推廣怎么快速拉人