Vue.js 如何拥有单个Vue组件,以及如何通过其他组件的按钮路由其中的每个内容
我是Vuejs新手,我希望通过使用一个vue组件来提高代码的效率,我只想指定一次路由 目前,我在应用程序指令中有一个info.vue,在更多指令中有一个prises.vue&prisehigh.vue。我想在更多指令中只包含一个组件。但问题在于info.vue我使用了两个按钮,每个按钮分别路由到prises.vue和prisehigh.vue。如下代码所示:Vue.js 如何拥有单个Vue组件,以及如何通过其他组件的按钮路由其中的每个内容,vue.js,routes,components,Vue.js,Routes,Components,我是Vuejs新手,我希望通过使用一个vue组件来提高代码的效率,我只想指定一次路由 目前,我在应用程序指令中有一个info.vue,在更多指令中有一个prises.vue&prisehigh.vue。我想在更多指令中只包含一个组件。但问题在于info.vue我使用了两个按钮,每个按钮分别路由到prises.vue和prisehigh.vue。如下代码所示: <vs-button class="btn" @click="$router.push({name:
<vs-button class="btn" @click="$router.push({name: 'prises'}).catch(err => {})" >Go To</vs-button>
<vs-button class="btn" @click="$router.push({name: 'priseshigh'}).catch(err => {})" >Go There</vs-button>
请将修改后的代码发送给我,以便我能轻松理解。您可以通过道具来路由组件
{
路径:'/apps/info/info more/prises card',
名称:'prises',
组件:()=>导入('./views/apps/info/more/prisecomplete.vue'),
道具:{
棱镜类型:“棱镜”
},
元:{
规则:“编辑”
}
},
{
路径:'/apps/info/info more/prisehigh card',
名称:“priseshigh”,
组件:()=>导入('./views/apps/info/more/prisecomplete.vue'),
道具:{
PriseType:“PriseHigh”
},
元:{
规则:“编辑”
}
}
PriseComplete.vue
撬
撬高
导出默认值{
名称:“PriseComplete”,
道具:{
棱镜类型:{
类型:字符串,
必填项:true
}
}
}
此外,您还可以使用to=“/path”
转到
去那里
您可以传递道具来路由组件
{
路径:'/apps/info/info more/prises card',
名称:'prises',
组件:()=>导入('./views/apps/info/more/prisecomplete.vue'),
道具:{
棱镜类型:“棱镜”
},
元:{
规则:“编辑”
}
},
{
路径:'/apps/info/info more/prisehigh card',
名称:“priseshigh”,
组件:()=>导入('./views/apps/info/more/prisecomplete.vue'),
道具:{
PriseType:“PriseHigh”
},
元:{
规则:“编辑”
}
}
PriseComplete.vue
撬
撬高
导出默认值{
名称:“PriseComplete”,
道具:{
棱镜类型:{
类型:字符串,
必填项:true
}
}
}
此外,您还可以使用to=“/path”
转到
去那里
首先,您需要为导航编写一个导航.vue
组件,并在应用程序内部使用routerview
进行渲染。看下面的句子和描述
导航.vue
<template>
<div>
<vs-button
class="btn"
@click="$router.push({ name: 'prises' }).catch((err) => {})"
>Prises</vs-button
>
<vs-button
class="btn"
@click="$router.push({ name: 'priseshigh' }).catch((err) => {})"
>Priseshigh</vs-button
>
</div>
</template>
首先,您需要为导航编写一个
navigation.vue
组件,并使用routerview
在应用程序内部进行渲染。看下面的句子和描述
导航.vue
<template>
<div>
<vs-button
class="btn"
@click="$router.push({ name: 'prises' }).catch((err) => {})"
>Prises</vs-button
>
<vs-button
class="btn"
@click="$router.push({ name: 'priseshigh' }).catch((err) => {})"
>Priseshigh</vs-button
>
</div>
</template>
非常感谢,但这不是我想要的。我的浏览器中显示了Info.vue组件。它包含两个按钮。因此,当我单击第一个按钮时,它将导航到prisesigh.vue,第二个按钮将导航到prisehigh.vue。现在,我想将prises.vue和prisehigh.vue合并为一个组件,并将其命名为prisecomplete.vue。现在,我的按钮仍应导航prisescomplete中prises&PriseHigh的内容。那么,我应该在routerlink和按钮中做哪些更改,以及如何在PriseComplete.if我没有错的情况下指定内容。。您需要为PriseComple.vue组件添加新路由器。是吗?是的,以及如何从prisecomplete.vue路由特定内容。正如我前面所说,如果我单击info.vue中的按钮,它将分别转到prises和prisehigh。但prises和PriseHigh的内容被视为PriseComplete。所以我想知道我应该更改什么路由,以及如何将特定内容从PriseComplete路由到按钮。你好,tuhin47我自己知道的,从你的回答中,我理解了这些事情是如何工作的,以及路由在实际中是如何发生的。现在你能给我一些关于这个的想法吗Hello@tuhin47,我有一个关于chartjs的问题,我想你可能有一些想法,这是URL,请帮助我,因为到目前为止我已经理解了你给我的所有答案。非常感谢你,但这不是我想要的。我的浏览器中显示了Info.vue组件。它包含两个按钮。因此,当我单击第一个按钮时,它将导航到prisesigh.vue,第二个按钮将导航到prisehigh.vue。现在,我想将prises.vue和prisehigh.vue合并为一个组件,并将其命名为prisecomplete.vue。现在,我的按钮仍应导航prisescomplete中prises&PriseHigh的内容。那么,我应该在routerlink和按钮中做哪些更改,以及如何在PriseComplete.if我没有错的情况下指定内容。。您需要为PriseComple.vue组件添加新路由器。是吗?是的,以及如何从prisecomplete.vue路由特定内容。正如我前面所说,如果我单击info.vue中的按钮,它将分别转到prises和prisehigh。但prises和PriseHigh的内容被视为PriseComplete。所以我想知道我应该更改什么路由,以及如何将特定内容从PriseComplete路由到按钮。你好,tuhin47我自己知道的,从你的回答中,我理解了这些事情是如何工作的,以及路由在实际中是如何发生的。现在你能给我一些关于这个的想法吗Hello@tuhin47,我有一个关于chartjs的问题,我想你可能有一些想法,这是URL,请帮助我,因为到目前为止我已经理解了你给我的所有答案。
<template>
<div id="app">
<TheNavigation/>
<hr>
<RouterView/>
</div>
</template>
<script>
import TheNavigation from "./components/TheNavigation";
export default {
name: "App",
components: {
TheNavigation
}
};
</script>
import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);
const router = new Router({
mode: "history",
routes: [
{
path: "/prises-card",
name: "prises",
component: () => import("./components/Prises.vue"),
meta: {
pageTitle: "info-more",
rule: "editor",
no_scroll: true
}
},
{
path: "/priseshigh-card",
name: "priseshigh",
component: () => import("./components/PrisesHigh.vue"),
meta: {
pageTitle: "info-more",
rule: "editor",
no_scroll: true
}
}
]
});
export default router;