vue.js - 如何重定向到vue js中的特定组件
问题描述
我想在不刷新页面的情况下在 URL 内重定向,而不使用如下路由器链接:
<router-link to="/about us " active-class="active">foo</router-link>
我想打印如下路线:
<li class="nav-item phone">
<a class="nav-link" href="contact-us.html">
اتصل بنا
</a>
</li>
我的路线:
const routes = [
{ path: '/aboutus/', component: AboutUs }
]
解决方案
您可能需要一个解决方法。
此解决方案不会改变url
任何一个:)
html
在数据中设置一个
data: () => {
return {
html: null
}
}
使用任何请求获取文件的内容html
并分配给html
indata
部分。您可以从任何生命周期挂钩中获取它。我在这里使用beforeMount
.
beforeMount() {
this.fetchAllEmployees();
axios.get('contact-us.html')
.then(response => {
this.html = response.data;
})
}
现在您可以html
像这样显示组件中的内容
<template>
<div>
<div v-html="html"></div>
</div>
</template>
要仅在单击a
标签时显示,您可以在data
其中添加另一个可用于切换值的变量。
推荐阅读
- python - 基于通用句子编码器的迁移学习模型无法保存到 TensorFlow 服务的 tf 模型
- python - 查找键失败 - 使用 elided_page 实现分页
- powershell - 为存储为字符串的 PS 脚本提供参数
- reactjs - xstate 将事件数据从服务传递到 onDone
- json - 如何从文本文件中的url检索json文件
- javascript - 将 JSON 保存到变量中,不包括 JSON 的某些元素
- python - 使用 PuLP 在 python 中最小化两个和
- python - 使用while循环检查python中其他两个数字之间的数字
- javascript - 我无法通过 https in express 访问路由
- linux - 无法在 Ubuntu 21.04 上安装 minion-nc 依赖项,考虑回滚到 Ubuntu 20.04