zoukankan      html  css  js  c++  java
  • 父组件与子组件传递参数

    组件的作用是提高代码的复用性,提高效率,在vue中使用组件可以通过如下的方法来传递参数
    <btn2 :a="Index" v-on:receive="changeValueHandle"></btn2>
    :a="Index"绑定父组件的Index到a中,然后子组件如下,通过props来接收a的参数
    Vue.component("btn2",{
    props: ['a'],
    template: '<button class="btn submit_btn" @click="submitShow(a)">' +
    '<slot>按钮</slot>'+
    '</button>',
    methods:{
    submitShow: function (a) {
    alert(a);
    this.$emit("receive");
    }
    }
    });
    在子组件中定义点击事件,然后在子组件进行这个操作的时候来把这个操作传给父组件,
    父组件通过 v-on:receive="changeValueHandle" 这样的写法来执行后续操作
    var vm=new Vue({
    el:".app",
    data:{
    Index:0,
    phoneVal:"123456"
    }
    methods:{
    changeValueHandle:function () {
    $.ajax({
    type:'post',
    url:"../json/js1.json",
    data:{
    phone:this.phoneVal
    },
    dataType:"json",
    success:function(data){
    alert(1);
    console.log(data);
    },
    error:function(error){
    console.log(error);
    }
    })
    }
    }
    });


  • 相关阅读:
    爬虫大作业
    数据结构化与保存
    使用正则表达式,取得点击次数,函数抽离
    爬取校园新闻首页的新闻
    网络爬虫基础练习
    综合练习:词频统计
    Hadoop综合大作业
    理解MapReduce
    熟悉HBase基本操作
    熟悉常用的HBase操作
  • 原文地址:https://www.cnblogs.com/qiuchuanji/p/7880488.html
Copyright © 2011-2022 走看看