vue.js - 在单个文件组件中使用路由器链接
问题描述
我被困在我的单文件组件中的路由器中,我试图在单文件组件中包含另一个组件,例如我已将thirdtemplate.vue 命名为我的SFC,并且我使用Vue.component(“newTemplate”,{template :"..."}),正如我在这篇文章中向下展示的示例。我需要在我的 newTemplate 组件中使用路由器链接,以便它调用组件 newTemplate 的模板。
<template>
<div>
<h4>hello this is from thirdTemplate</h4>
<router-link to="/secondTemplate">Go to secondTemplate</router-link>
<router-link to="/thirdTemplate">Go to thirdTemplate</router-link>
<newtemplate></newtemplate>
</div>
</template>
<script>
Vue.component("newtemplate", {
template: "<template><div><button>hello</button></div></template>"
});
module.exports = {
name: "thirdTemplate",
methods: {},
components: {}
};
</script>
解决方案
将此代码移动到定义新 Vue 构造函数的 main.js
Vue.component("newtemplate", {
template: "<template><div><button>hello</button></div></template>"
});
并为您的路由器配置第一个模板和第二个模板
推荐阅读
- python - 如何将列表的长度乘以一个数字
- outlook-web-addins - 通过基于 javascript 的 Outlook-addin 创建类别
- multicore - gem5模拟中不同内核的不同频率?
- swagger - 如何在 swagger-ui 中更改缓存控制
- python - 如何通过代码获取odoo中的自定义插件路径
- node.js - Docker-compose 部署 redis 但 app.js 拒绝连接
- algorithm - 安排面试算法以最小化面试中的申请人数量
- c++ - 如何使用 LLDB 进入最外层的函数调用?
- android - 毕加索不适用于 1.bp.blogspot.com 网址
- python - 按下数据清洗按钮时如何显示数据清洗结果表?