美文网首页
03、vue 页面跳转传值,父子组件传值

03、vue 页面跳转传值,父子组件传值

作者: 蜗牛的学习方法 | 来源:发表于2018-11-29 15:40 被阅读0次

1、页面跳转传参

//使用path跳转 只能用query 传参  ,用params传参参数传不过去 
优点是不会显示在url上面
缺点是 一刷新页面参数就没有l
this.$router.push({path: '/addPrice',query:{ id:'1'}});
//使用name跳转 ,用query和params跳转都行

// 但是query跳转的页面参数会显示在url上面,但是params却不会
优点和上面的刚好相反
this.$router.push({name: 'AddPrice',params:{ id:'1'}});

2、父子组件传值
父组件

<div>
    <Headers name="首页" right="新建" @rightBtn="sayHello"></Headers>
</div>
<script >
methods: {
  sayHello() {
      console.log('父组件‘)
    }
}
</script>

子组件(子组件调用父组件的方法)

<template>
  <mt-header fixed :title="name">
    <router-link to="/" slot="left">
      <mt-button icon="back"></mt-button>
    </router-link>
    <mt-button  slot="right" @click.native="childClick">{{right}}</mt-button>
  </mt-header>
</template>

<script>
    import { Header } from 'mint-ui';
    export default {
        name: "Headers",
        props: ['name','right'],
        components:{
          Header,
        },
        methods:{
          childClick(){
            this.$emit('rightBtn')
          }
        }
    }
</script>

<style scoped>

</style>

3、父组件调用子组件的方法

//父组件
<Strategy ref='strategyChild' :consitionList="consitionList"/>
<button @click="clickParent">点击</button>

methods:{
  clickParent() {
        this.$refs.strategyChild.childClick("嘿嘿嘿");
      }
}
//子组件
 methods:{
      childClick(e) {
          console.log(e)
      }
  }

4、修改浏览器的title
//修改浏览器的头部

Vue.directive('title', {
  inserted: function(el, binding) {
    document.title = binding.value
  }
})
或者
document.title='首页'

相关文章

  • Vue父子组件通信和双向绑定

    本篇文章主要介绍父子组件传值,组件的数据双向绑定。 1. 基础父子组件传值 父子组件传值,这是Vue组件传值最常见...

  • 小程序自定义组件

    1、组件声明 页面json文件--usingComponents属性 2、父子组件传值 父向子传值,类似vue,父...

  • (VUE3) 四、组件传值(父子组件传值 & 祖孙组件传值 &v

    1.父子组件传值 vue2中的父子组件传值:父组件: 子组件: vue3中的父子组件传值: 还是用props接收父...

  • 03、vue 页面跳转传值,父子组件传值

    1、页面跳转传参 2、父子组件传值父组件 子组件(子组件调用父组件的方法) 3、父组件调用子组件的方法 4、修改浏...

  • 组件通信

    vue传值可分为父子之间传值、兄弟组件之间传值、跨代组件之间传值 1.父子之间传值:可以使用$emit/props...

  • VUE组件(传值,生命周期)

    VUE生命周期 VUE子传父组件通信 VUE非父子组件传值

  • 前端基础搬运工-VUE模块

    十、VUE模块 基础部分 1. Vue组件间传值 答: -[ ] 1.父子之间的传值 父组件向子组件传值通过p...

  • vue2.0的三种常用传值方式,并且如何实现?

    vue2.0 组件传值方式有三种:父组件向子组件传值,子组件向父组件传值,非父子组件传值 : 父传子: 首先现在父...

  • 2019-03-13

    vue父子组件传值,(父组件向子组件传值用prop ,子组件向父组件传值:子组件调用父组件方法值以参数的方式传递)...

  • 2019-03-13

    vue父子组件传值,(父组件向子组件传值用prop ,子组件向父组件传值:子组件调用父组件方法值以参数的方式传递)...

网友评论

      本文标题:03、vue 页面跳转传值,父子组件传值

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