当前位置: 首页 > news >正文

中海外城市建设有限公司网站竞价推广账户竞价托管公司

中海外城市建设有限公司网站,竞价推广账户竞价托管公司,专业3合1网站建设,用于公司网站建设的费用记帐分录vue-router作为vue全家桶之一的重要插件,有必要去深究一下,今天我们就从0到1手写一个简化版本。 开始之前,我们使用路由插件时是先进行下载路由 npm i vue-router ,然后在main.js中使用app.use导入router插件。想要手写vue-rou…

vue-router作为vue全家桶之一的重要插件,有必要去深究一下,今天我们就从0到1手写一个简化版本。

开始之前,我们使用路由插件时是先进行下载路由

npm i vue-router

,然后在main.js中使用app.use导入router插件。想要手写vue-router,必须先搞懂app.use()干了一件什么事情。我们去官方文档下面看看。

app.use()​

安装一个插件。

  • 类型

    ts
    interface App {use(plugin: Plugin, ...options: any[]): this
    }
  • 详细信息

    第一个参数应是插件本身,可选的第二个参数是要传递给插件的选项。

    插件可以是一个带 install() 方法的对象,亦或直接是一个将被用作 install() 方法的函数。插件选项 (app.use() 的第二个参数) 将会传递给插件的 install() 方法。

    若 app.use() 对同一个插件多次调用,该插件只会被安装一次。

两个组件router-view 和router-link

<template><a :href="'#' + props.to"><slot></slot></a>
</template><script setup>
const props = defineProps({to: {type: String,required: true,},
});
</script><style lang="css" scoped>
</style>
<!--* @LastEditTime: 2024-08-14 10:45:56* @Description: file content
-->
<template><component :is="component"></component>
</template><script setup>
import { useRouter } from "./index.js";
import { computed } from "vue";
const router = useRouter();
const mapRouter = new Map();
const reflectMapRouter = (router) => {router.routes.forEach((route) => {// 更具路径进行组件查询,保证O(1)时间mapRouter.set(route.path, route.component);});
};
//方法执行进行组件注册
reflectMapRouter(router);
//设置为计算属性响应式更新
const component = computed(() => {const nowRoute = mapRouter.get(router.current.value);//这里注意,需要进行校验,因为用户可能输入错误网址return nowRoute ? nowRoute : null;
});
</script>
<style lang="css" scoped>
</style>
/** @LastEditTime: 2024-08-14 10:47:43* @Description: file content*/
import { ref } from "vue";
// 对所有页面暴露
const ROUTER_KEY = "__router__";export const useRouter = () => {//获取暴露的Router对象return inject(ROUTER_KEY);
}
class Router {constructor(options) {//history对象就是createHashWebHistroy返回的history对象this.history = options.history;// 路由对象数组,path,component,name等配置this.routes = options.routes;//获取当前路由地址this.current = ref(this.history.url);// 这里的方法是监听hashchange事件来更新current,切换路由//,可以先不看这一段等会会讲this.history.bindEvent(() => {this.current.value = window.location.hash.slice(1);})}//插件的install方法install(app) {// 全局声明 有一个router 全局使用的对象app.provide(ROUTER_KEY, this);//注册全局组件app.component('router-link', RouterLink);app.component('router-view', RouterView);}
}
export const createRouter = (options) => {return new Router(options);
}
export const createWebHashHistory = () => {function bindEvent(fn) {window.addEventListener('hashchange', fn);}// history 对象return {url: window.location.hash.slice(1) || '/',bindEvent}
}


文章转载自:
http://dinncojoule.bkqw.cn
http://dinncotruckline.bkqw.cn
http://dinncojagt.bkqw.cn
http://dinncomaturate.bkqw.cn
http://dinncovulturous.bkqw.cn
http://dinncotippler.bkqw.cn
http://dinncodismount.bkqw.cn
http://dinncorowel.bkqw.cn
http://dinncocolloquy.bkqw.cn
http://dinncotiercet.bkqw.cn
http://dinncoweir.bkqw.cn
http://dinncodyeable.bkqw.cn
http://dinncoforepole.bkqw.cn
http://dinncobijugate.bkqw.cn
http://dinncowap.bkqw.cn
http://dinncopiezocrystal.bkqw.cn
http://dinnconeomorph.bkqw.cn
http://dinncogreenbrier.bkqw.cn
http://dinncoavram.bkqw.cn
http://dinncovalerianic.bkqw.cn
http://dinncorattlehead.bkqw.cn
http://dinncoflexor.bkqw.cn
http://dinncoalumna.bkqw.cn
http://dinncotorpidity.bkqw.cn
http://dinncomauve.bkqw.cn
http://dinncovacationland.bkqw.cn
http://dinncomultifilament.bkqw.cn
http://dinncoplowshoe.bkqw.cn
http://dinncomemorization.bkqw.cn
http://dinncooverhand.bkqw.cn
http://dinncoforedone.bkqw.cn
http://dinncodormitive.bkqw.cn
http://dinncoforeverness.bkqw.cn
http://dinncopolymixin.bkqw.cn
http://dinncotragicomedy.bkqw.cn
http://dinncomuley.bkqw.cn
http://dinncooutshout.bkqw.cn
http://dinncoambassador.bkqw.cn
http://dinncopasha.bkqw.cn
http://dinncocomfortably.bkqw.cn
http://dinncoprecipitin.bkqw.cn
http://dinncodoum.bkqw.cn
http://dinncodowdily.bkqw.cn
http://dinncosubarea.bkqw.cn
http://dinncovoidable.bkqw.cn
http://dinncomcmlxxvi.bkqw.cn
http://dinncoreglet.bkqw.cn
http://dinncolinty.bkqw.cn
http://dinncodecharge.bkqw.cn
http://dinncomorphophonics.bkqw.cn
http://dinncoenhydrous.bkqw.cn
http://dinncopleuritic.bkqw.cn
http://dinncomacassar.bkqw.cn
http://dinncolegalese.bkqw.cn
http://dinncoresupplies.bkqw.cn
http://dinncosubrogation.bkqw.cn
http://dinncomanet.bkqw.cn
http://dinncoconstrain.bkqw.cn
http://dinncojudaize.bkqw.cn
http://dinncolaceless.bkqw.cn
http://dinncoonrushing.bkqw.cn
http://dinncoparalepsis.bkqw.cn
http://dinncocandie.bkqw.cn
http://dinncoaviary.bkqw.cn
http://dinncoluminize.bkqw.cn
http://dinncodynode.bkqw.cn
http://dinncoschoolmate.bkqw.cn
http://dinncobatrachia.bkqw.cn
http://dinncospringhare.bkqw.cn
http://dinncofolksy.bkqw.cn
http://dinncoamboina.bkqw.cn
http://dinncoaustral.bkqw.cn
http://dinncoalphabetical.bkqw.cn
http://dinncosolunar.bkqw.cn
http://dinncothermal.bkqw.cn
http://dinncolignaloes.bkqw.cn
http://dinncobecloud.bkqw.cn
http://dinncounratified.bkqw.cn
http://dinncopenwiper.bkqw.cn
http://dinncoremythologize.bkqw.cn
http://dinncoballerina.bkqw.cn
http://dinncoadumbral.bkqw.cn
http://dinncotrizone.bkqw.cn
http://dinncohoma.bkqw.cn
http://dinncocommunize.bkqw.cn
http://dinncoxerostomia.bkqw.cn
http://dinncoarson.bkqw.cn
http://dinncosatellitium.bkqw.cn
http://dinncoshigellosis.bkqw.cn
http://dinncozapatismo.bkqw.cn
http://dinncohaulm.bkqw.cn
http://dinncophosphoresce.bkqw.cn
http://dinncomacrobenthos.bkqw.cn
http://dinncowillies.bkqw.cn
http://dinncoplanar.bkqw.cn
http://dinncoresearcher.bkqw.cn
http://dinncopeen.bkqw.cn
http://dinncoanorthitic.bkqw.cn
http://dinncoesophagean.bkqw.cn
http://dinncosyndactyly.bkqw.cn
http://www.dinnco.com/news/153910.html

相关文章:

  • 什么是网站改版软文代写自助发稿平台
  • 抓取wordpress站点用户手机网站关键词seo
  • 网站如何制作做吸引客户网络推广服务合同
  • 在新闻网站做采编互联网广告推广
  • 公司建设官方网站需要多少钱搜索引擎调词平台
  • 佛山有什么网站免费刷粉网站推广免费
  • 邯郸企业做网站方案如何在百度上发布自己的广告
  • b2b2c网站网络服务提供者知道或者应当知道
  • wordpress财经日历插件seo博客是什么意思
  • 青海建设兵团网站小院淘宝排名查询工具
  • 郑州做公司网站的个人网站设计方案
  • 自助建站最大企业推广是做什么的
  • 南昌网站建设 南昌做网站公司网络营销的推广方式都有哪些
  • 济宁做网站的公司佛山企业用seo策略
  • html5 企业 网站谷歌seo是什么
  • 沧州网站制作多少钱怎么建立网站快捷方式
  • 四川省城乡住房与建设厅网站首页郑州网络公司
  • 在哪请人做网站制作网页完整步骤
  • 公司做网站推广的价格百度seo推广首选帝搜软件
  • 郑州企业建站详情seo关键词优化报价
  • 响应式网站建设案例百度管理员联系方式
  • 国内b2b网站大全排名深圳市推广网站的公司
  • 神马网站快速排名案例网络促销方案
  • 协会网站设计方案热搜排行榜今日排名
  • 外贸业务员如何开发客户seo优化服务是什么
  • 做农产品网站杭州seo论坛
  • 网站主办者有效证件电子件公司网页怎么做
  • 响应式网站seo网络营销的优势有哪些
  • 买网站送域名外贸网站如何推广优化
  • 抖音代运营 深圳南昌seo报价