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

如何在电脑上制作网页关键词排名优化系统

如何在电脑上制作网页,关键词排名优化系统,wordpress backup,网站流量太大目录 前言1. unref2. Demo 前言 从实战中学习,了解一点点知识点 unref 主要用于解包 ref,特别是在 Vue Router 4 里,currentRoute 是一个响应式 ref,需要 .value 或 unref 来访问具体字段 1. unref unref 是 Vue 3 提供的工具函…

目录

  • 前言
  • 1. unref
  • 2. Demo

前言

从实战中学习,了解一点点知识点

在这里插入图片描述

unref 主要用于解包 ref,特别是在 Vue Router 4 里,currentRoute 是一个响应式 ref,需要 .value 或 unref 来访问具体字段

1. unref

unref 是 Vue 3 提供的工具函数,可以解包 ref 值,即:

  • 如果传入的是 ref,返回 ref.value
  • 如果传入的不是 ref,直接返回原值
import { ref, unref } from 'vue'const count = ref(10)console.log(count.value) // 10
console.log(unref(count)) // 10console.log(unref('Hello Vue 3')) // 'Hello Vue 3' (非 ref 直接返回)

再者为什么 currentRoute 需要 unref?
为何要用unref来解析呢

在 Vue Router 4 里,useRouter().currentRoute 是一个 ref 对象,用于存储当前路由信息

const router = useRouter()
console.log(router.currentRoute) // 这是一个 ref 对象
console.log(router.currentRoute.value) // 访问当前路由信息

由于 currentRoute 是 ref,所以要获取 name、path 等字段时,可以使用:

const { name } = router.currentRoute.value

或者:

const { name } = unref(router.currentRoute)

它的实际应用放在监听当前路由变化,或者访问 name、path、meta 等字段

import { unref } from 'vue'
import { useRouter } from 'vue-router'const { currentRoute } = useRouter()console.log(unref(currentRoute)) // 打印完整的当前路由对象
console.log(unref(currentRoute).name) // 获取路由 name

2. Demo

具体小例子:

<script setup lang="ts">
import { ref, watch, onMounted, unref } from 'vue'
import { useRouter, useRoute } from 'vue-router'const router = useRouter()
const route = useRoute()const routeName = ref('')
const routePath = ref('')// 监听 currentRoute 变化
watch(() => route.name, (newName) => {routeName.value = newName as stringconsole.log('当前路由 name:', newName)
})watch(() => route.path, (newPath) => {routePath.value = newPathconsole.log('当前路由 path:', newPath)
})// 在 mounted 阶段输出初始值
onMounted(() => {console.log('完整的路由对象:', unref(router.currentRoute))console.log('当前路由 name:', unref(router.currentRoute).name)console.log('当前路由 path:', unref(router.currentRoute).path)
})
</script><template><div><h2>当前路由信息</h2><p>路由名称: {{ routeName }}</p><p>路由路径: {{ routePath }}</p></div>
</template>
http://www.dtcms.com/wzjs/461905.html

相关文章:

  • 开发b2c网站建设厦门专业做优化的公司
  • 新电商运营与推广优化设计答案大全英语
  • 网站建设岗位职责怎么写平台推广公众平台营销
  • 网站弹窗设计百度站长工具添加不了站点
  • 平台补单seo优化网络公司
  • 西安网站空间广告推广计划
  • 请被人做网站淄博seo
  • 新公司在哪做网站刷关键词指数
  • 自己怎么做商城网站吗百度不收录网站
  • 政和网站建设seo网站推广服务
  • 日本人主流浏览器苹果aso优化
  • 网站关键词在哪里做搜索引擎优化的主要内容
  • 怎么做微网站百度电脑版
  • 信用网站建设搜索引擎推广简称
  • 西安网站设计培训试听网络推广方案范文
  • 基金会网站建设站长工具传媒
  • 做慕斯蛋糕那个网站有视频百度电话客服24小时人工
  • 网站开发流程详细介绍沧州网站推广优化
  • 一个人可做几次网站备案成品短视频app源码的优点
  • 免费外贸网站源码seo咨询价格找推推蛙
  • 陕西旭泽建设有限公司网站新媒体平台
  • 做网站运营难吗应用商店app下载
  • 搭建一个网站的服务器广州市运营推广公司
  • 做网站的要求安卓优化大师老版本下载
  • 我的网站在百度搜不到南通企业网站制作
  • 网站开发 上海优化搜索引擎的方法
  • 青海西宁制作网站企业百度小说排行榜总榜
  • 中山商城型网站建设百度浏览器下载
  • 网站建设与制作教程吕磊域名怎么查
  • 用香港服务器建网站做微商百度关键词seo排名优化