zoukankan      html  css  js  c++  java
  • 有关vue (父子组件传值)

    模板 挂载点 实例
    v-html v-text {{}} 插值表达式
    v-on:click=" " v-on(“@”) 绑定事件
    v-bind:title=" " v-bind(“:”) 属性绑定
    v-model = " " (双向数据绑定)
    计算属性 computed:
    侦听器 watch:
    v-if(把标签去除)
    v-show(display:none)
    v-for=“item of list”
    每个vue组件都是实例

    父组件向子组件传值与子组件向父组件传值的实例:

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script src="./vue.js"></script>
    </head>
    <body>
    <div id="root">
        <input v-model="msg"/>
        <button @click="xianshi">提交</button>
        <ul >
            <!--<li>{{item}}</li>-->
            <h-item v-for="(item,index) of list"
                    :key="index"
                    :content="item"
                    :index = "index"
                    @delete="fdelete"
            ></h-item>
        </ul>
    </div>
    
    <script>
    
        Vue.component('h-item',{
            props:['content','index'],
            template:" <li @click='shanchu'>{{content}}</li>",
            methods:{
                shanchu:function(){
                    this.$emit('delete',this.index);
                    // console.log(this.index);
                }
            }
        })
        new Vue({
            el:"#root",
            data:{
               msg:'',
                list:[]
            },
            methods:{
                xianshi:function(){
                   this.list.push(this.msg);
                   this.msg='';
                },
                fdelete: function(index){
                    this.list.splice(index,1);
                    console.log(index);
                }
            }
        })
    
    </script>
    </body>
    </html>
    
  • 相关阅读:
    洛谷 P1692 部落卫队
    洛谷 P1113 杂务
    洛谷 P1546 最短网络 Agri-Net
    洛谷 P2121 拆地毯
    洛谷 P2728 纺车的轮子 Spinning Wheels
    洛谷 P2126 Mzc家中的男家丁
    线段树双标记——乘法和加法
    A. Feed the cat
    洛谷 P1535 游荡的奶牛
    BZOJ1050 [HAOI2006]旅行
  • 原文地址:https://www.cnblogs.com/princeness/p/11664955.html
Copyright © 2011-2022 走看看