美文网首页
Vue Cli传参

Vue Cli传参

作者: 秋玄语道 | 来源:发表于2019-04-29 16:40 被阅读0次
一、页面跳转传参

params(返回不需要带参),query(带查询参数)
1、 第一个页面:

<router-link :to="{name:'Management',params:{userId:this.userId}}">
        <div>跳到第二个页面</div>
</router-link>

第二个页面:

 created: function () {console.log(this.$route.params.userId)}  //返回页不需要参数
 created: function () {console.log(this.$route.query.userId)}  // 带查询参数,变成 /register?plan=private

2、第一个页面:

<div @click="routerLink">跳转到第二个页面</div>
methods:{
    routerLink:function(){
      this.$router.push({ name: 'Detail', params: { userId: this.userId}})
    }
}

第二个页面:

created: function () {
      console.log("userId:"+this.$route.params.userId); 
}
二、数据传递

1、子组件向父组件传值

子: <span>{{childValue}}</span>
    <!-- 定义一个子组件传值的方法 -->
    <input type="button" value="点击触发" @click="childClick">
     methods: {
       childClick () {
         this.$emit('childByValue', this.childValue)
        }
    }
父: <child v-on:childByValue="childByValue"></child>
     methods: {
      childByValue: function (childValue) {
        // childValue就是子组件传过来的值
        this.name = childValue
       }
     }

2、父组件向子组件传值

父:<child :inputName="name"></child>
子:<span>{{inputName}}</span>
    export default {
    // 接受父组件的值
    props: {
      inputName: String,  //数组就是Array等等
      required: true
    }
  }

3、非父子传值(vuex或者bus)

相关文章

  • Vue Cli传参

    一、页面跳转传参 params(返回不需要带参),query(带查询参数)1、 第一个页面: 第二个页面: 2、第...

  • 31.vue传参

    1.vue传参 vue传参使用路由传参params,query,或者使用vuex,localStorage,vue...

  • vue-router

    1. vue-router query 和 params 传参 params 传参: 总结: 用params传参只...

  • vue - 路由带参跳转

    vue路由传参按照传参方式可划分为params传参和query传参; params传参分为在url中显示和影藏参数...

  • vue-router总结

    1、通过 :to 传参 2、通过URL传参 router/index.js App.vue Hi.vue 重定向 ...

  • vue 页面传参,不通过路由传参

    1,vue 传参,不通过路由传参 1,项目文件结构 2,list.vue 文件 3,... tab1.vue 文件

  • 路由传参 query 和 params

    vue路由传参分为两种情况: 一、query和params传参的区别: 1、query传参显示参数,params传...

  • vue-router

    vue传参两种方式 1、对象传参2、路径传参 vue路由两种模式 1、hash模式 onhashchange2、h...

  • SSM单体架构项目 (下)

    Vue 组件 组件导入 组件传参 props 组件传参,父组件向子组件传参 分页 引入分页组件

  • vue中计算属性computed方法内传参

    原文:vue中计算属性computed方法内传参 vue中computed计算属性无法直接进行传参 如果有传参数的...

网友评论

      本文标题:Vue Cli传参

      本文链接:https://www.haomeiwen.com/subject/ehxunqtx.html