首页 > 其他分享 >vue 列表页面点击编辑页面传值

vue 列表页面点击编辑页面传值

时间:2022-11-26 16:57:16浏览次数:55  
标签:vue name title props id 传值 页面

props分为三种形式

  • props为对象
  • props为布尔值,这种只能接收params动态路由的参数
  • props为函数,可以接收query和params参数(推荐)
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    props: {
      name: "张三",
      age: 20,
      addr:'河南省信阳市商城县李集乡新庄村'
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: '/detail/:id/:title',
    name: 'detail',
    // props是个布尔值
    // props:true,
    props($route){
      return {
        id:$route.params.id,
        title:$route.params.title
      }
    },
    component: () => import(/* webpackChunkName: "detail" */ '../views/Detail.vue')
  },
  {
    path: '/mine',
    name: 'mine',
    props($route){
      return {
        id:$route.query.id,
        title:$route.query.title
      }
    },
    component: () => import(/* webpackChunkName: "detail" */ '../views/Mine.vue')
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router

about(props为对象的时候)

 <template>
  <div class="about">
    <h1>This is an about page</h1>
    <ul>
      <li>{{name}}</li>
      <li>{{age}}</li>
      <li>{{addr}}</li>
    </ul>
    <router-link :to="{
      name:'detail',
      params:{
        id: 1,
        title:'张三'
      }
    }">
      跳转detail页面
    </router-link>
    <router-link :to="{
      path:'/mine',
      query:{
        id: 1,
        title:'张三'
      }
    }">
      跳转mine页面
    </router-link> 
  </div>
</template>
<script>
export default {
  props: {
    name: {
      type: String,
    },
    age: {
      type: Number,
    },
    addr: {
      type: String,
    },
  },
}
</script>

 

detai(props为布尔值,注意这种只能接收params参数)

<template>
  <div class="detail">
   <h1>详情页面</h1>
   <ul>
    <li>id: {{id}}</li>
    <li>title: {{title}}</li>
   </ul>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: 'Detail',
  components: {},
  props: {
    id: {
      type: [Number,String],
    },
    title: {
      type: String,
    },
  }
}
</script>

  

mine页面(props为函数的时候,可以接收query参数和params参数)

<template>
  <div class="mine">
   <h1>我的页面</h1>
    <ul>
      <li>id: {{id}}</li>
      <li>title: {{title}}</li>
   </ul>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: 'Mine',
  components: {},
  props: {
    id: {
      type: [Number,String],
    },
    title: {
      type: String,
    },
  }
}
</script>

  

 

标签:vue,name,title,props,id,传值,页面
From: https://www.cnblogs.com/elsons/p/16927713.html

相关文章

  • vue路由传参的三种写法
    methods:{goSearch(){//1.路由传参字符串形式//this.$router.push("/Search/"+this.keyword+"?k="+this.keyword.toUpp......
  • vue tab 切换
    <template><view><!--内容--><viewclass="content_box"><viewclass="content"><!--分类--><view......
  • 5-6 显示html页面-使用post实现登录
    1.创建自己的应用(app)文件夹执行下面的命令,将自动生成对应的文件夹polls是应用名称,可以自己更改pythonmanage.pystartapppolls在主文件中settings中添加应用......
  • vue3中watch监听不是你想的那样简单
    vue3中watch监听数组,数组变化后未触发回调今天发生了一个很神奇的现象,就是我使用watch监听数组时。被监听的数组已经发生了变化。但是没有触发回调操作。当时的我感到很疑......
  • vue3中watch监听不是你想的那样简单
    vue3中watch监听数组,数组变化后未触发回调今天发生了一个很神奇的现象,就是我使用watch监听数组时。被监听的数组已经发生了变化。但是没有触发回调操作。当时的我感到很疑......
  • vue3踩坑记录
    VueGridLayout-️适用Vue.js的栅格布局系统'.sync'modifieron'v-bind'directiveisdeprecated.Use'v-model:propName'instead.eslint-plugin-vue在3.x中,自......
  • vue框架中:点击图片使得图片放大展示方法
    安装插件cnpminstallv-viewer--save使用npm方式安装可能会报错,安装不上在main.js引用importViewerfrom'v-viewer'import'viewerjs/dist/viewer.css'//Vue.us......
  • Vue组件命名规范之大小写
    定义组件名的方式有两种:使用kebab-caseVue.component('my-component-name',{/*...*/})当使用kebab-case(短横线分隔命名)定义一个组件时,你也必须在引用这个自......
  • Vue组件命名规范之大小写
    定义组件名的方式有两种:使用kebab-caseVue.component('my-component-name',{/*...*/})当使用kebab-case(短横线分隔命名)定义一个组件时,你也必须在引用这个自......
  • Vue组件命名规范之大小写
    定义组件名的方式有两种:使用kebab-caseVue.component('my-component-name',{/*...*/})当使用kebab-case(短横线分隔命名)定义一个组件时,你也必须在引用这个自......