您可以在网格中提供Vue路由器链接,但是您需要确保为正在创建的Grid组件提供一个路由器。
使用示例代码:
// create a new VueRouter, or make the "root" Router available
import VueRouter from "vue-router";
const router = new VueRouter();
// pass a valid Router object to the Vue grid components to be used within the grid
components: {
'ag-grid-vue': AgGridVue,
'link-component': {
router,
template: '<router-link to="/master-detail">Jump to Master/Detail</router-link>'
}
},
// You can now use Vue Router links within you Vue Components within the Grid
{
headerName: "Link Example",
cellRendererFramework: 'link-component',
width: 200
}这里缺少的是如何使“根”路由器可用。我一直在调查不同的来源,发现很多人都有同样的问题,但没有一个人得到了明确的答案。
https://github.com/ag-grid/ag-grid-vue/issues/1
https://github.com/ag-grid/ag-grid-vue/issues/23
https://github.com/ag-grid/ag-grid-vue-example/issues/3
https://forum.vuejs.org/t/vue-cant-find-a-simple-inline-component-in-ag-grid-vue/21788/10
ag-grid-vue是否仍然与vue-路由器一起工作,那么如何工作,还是这只是过时的文档?有些人声称它对他们有效,所以我认为它曾经起过作用。
在这一点上,我不是在寻找冷静的答案。我只想知道这是否可能。我尝试过使用窗口传递路由器,或者创建了(),但是到目前为止都没有起作用。
谢谢!
发布于 2018-09-06 19:49:03
@氧点推荐的方法效果很好。唯一的缺点是用户不能右键单击,但我发现您可以只定义href链接。所以当你左键点击时,事件侦听器就会使用路由器.当您在新选项卡中右键单击并打开时,浏览器将接受href链接.
您仍然需要使您的根路由器可用。下面的代码示例假设您在Vue -路由器感知的Vue组件中包含了消耗ag网格的代码,因此.$路由器指向根路由器。
{
headerName: 'ID',
field: 'id',
cellRenderer: (params) => {
const route = {
name: "route-name",
params: { id: params.value }
};
const link = document.createElement("a");
link.href = this.$router.resolve(route).href;
link.innerText = params.value;
link.addEventListener("click", e => {
e.preventDefault();
this.$router.push(route);
});
return link;
}
}https://stackoverflow.com/questions/52121719
复制相似问题