vue两组件间值传递 $router.push实现方法(2)

import Vue from "vue"; interface Iscenes { id: string; name: string; selected: boolean; } export default Vue.extend({ data() { const sceneOption: Iscenes[] = [{ id: "1", name: "场景1", selected: false, },{ id: "2", name: "场景2", selected: false, },{ id: "3", name: "场景3", selected: false, }]; return { form: { name: "", initScene: "", }, sceneOption, }; }, created() { const {label= "", scene= ""} = this.$route.query; this.form = { name: label.toString(), initScene: scene.toString(), }; }, watch: { $route(to, from) { if (to.path === "/list/listEdit") { const {label= "", scene= ""} = to.query; this.form = { name: label.toString(), initScene: scene.toString(), }; } }, }, methods: { submitForm() { console.log("test"); } }, });

最后,再来看一下,路由部分的配置:

import ListDetail from "../views/list-detail/index.vue"; import List from "../views/list/index.vue"; import { MenuConfig } from "./index"; export const listRouter: MenuConfig = { path: "/list", component: List, title: "目录管理", key: "list", name: "list", hasPermission: true, subShow: false, children: [{ path: "listEdit", title: "编辑目录", hasPermission: true, name: "ListEdit", key: "ListEdit", component: ListDetail, }], };

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/7b8e2ea2a677432c7ebaac5f71fafa2f.html