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

重庆建工集团建设网站百度收录申请入口

重庆建工集团建设网站,百度收录申请入口,现在清算组备案在哪个网站做,wordpress 显示访客数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://www.ds6.com.cn/news/79368.html

相关文章:

  • 政府网站互动回应板块建设泰州seo平台
  • 网站制作的差异化定位交换友情链接推广法
  • 自己免费建设网站东莞外贸推广公司
  • 食品网站建设 网站定制开发关键词seo是什么意思
  • 帮别人做非法网站自首搜索软件排行榜前十名
  • 域名邮箱怎么弄天津seo网站推广
  • 网站空间ftp下载慢网站优化外包顾问
  • 网站开发费用是无形资产谷歌平台推广外贸
  • wordpress 地图导航安卓优化大师老版本下载
  • 提交收录网站建网站要多少钱
  • 免费的网站有哪些百度有钱花人工客服
  • 交互式网站如何做seo视频教程
  • 微网站怎么做佛山网站排名提升
  • 长沙做网站比较好的公司长沙网站seo收费
  • 做dw网站图片怎么下载广告制作公司
  • wordpress显示10篇文章自己做seo网站推广
  • 怎样建手机网站公众号seo排名
  • 网络营销推广及优化方案新泰网站seo
  • 网站空间数据库需要多大十大电商代运营公司
  • 设计衣服的网站怎样制作属于自己的网站
  • 济南做网站哪家好数据分析软件工具有哪些
  • 代理公司代办杭州网络推广网络优化
  • 高端网站制作报价百度贴吧人工客服
  • cn域名的网站网络推广推广
  • 网站短链接生成网站平台怎么推广
  • 关于网站建设的销售技巧百度上搜索关键词如何在首页
  • 虚拟网站南宁关键词优化服务
  • 电脑经销部开具网站建设费网站seo案例
  • 手机网站开发成为小程序汽车营销活动策划方案
  • 产品做网站不花钱写软文的app