zoukankan      html  css  js  c++  java
  • vue props传值方法

    <template>
      <div class="hello">
        	<ul>
        		<li 
        			v-for="(item, index) in type"
        			@click="handle($event)"
        			@touchMove='touchMove' 
        			>{{item.main}} --{{index}}</li>
        	</ul>
        	<div class="tabc">
        			<Tabs :text="type" :mmmmmm="msg"></Tabs>  //key/value
        	</div>
      </div>
    </template>
    
    <script>
    	import Tabs from './tabs';
    export default {
      name: 'HelloWorld',
      components:{
      	Tabs
      },
      data (){
        return {
          	type:[
          		{main:"切换1"},
          		{main:"切换2"},
          		{main:"切换3"}
          	],
          	msg:"我是父组件的值"  //要传入的值
        }
      },
      methods:{
      	handle($event){
      		console.log($event.offsetX)
      		console.log($event.offsetY)
      		console.log($event.type)
      		console.log($event)
      	},
      	touchMove(ev) {
            ev = ev || event;
            ev.preventDefault();
    //      let btnWidth = this.$refs.remove.offsetWidth;  //$refs 减少获取dom节点的消耗
    //      let btnImg = this.$refs.btnImg.offsetWidth;
            console.log(ev);
    //      console.log(btnWidth);
            
           }
        },
      }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    h1, h2 {
      font-weight: normal;
    }
    ul {
      list-style-type: none;
      padding: 0;
    }
    li {
      background: #ddd;
      margin-bottom: 0px;
      height: 40px;
      line-height: 40px;
    }
    a {
      color: #42b983;
    }
    </style>
    

      

    <template>
      <div class="hehe">
      		<h4>{{mmmmmm}}</h4>
        	<ul>
        		<li v-for="(item,index) in text">{{item.main}}</li>
        	</ul>
      </div>
    </template>
    
    <script>
    export default {
      name: 'hehe',
      props: {      
      	text:{    //此处为要接收的值   text为接收过来key 
      		type:Array,   //key不能乱写
      		default:''
      	},
      	mmmmmm:{  //同上
      		type:String,
      		default:'我是默认值'
      	}
      	
      },
      data () {
        return {
        	hehe:"222"
        }
      },
      methods:{
      	
    
      }
     }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    ul,li{
    	list-style: none;
    }
    ul{
    	display: flex;
    	align-items: center;
    	margin-top: 5px;
    }
    
    li{
    	flex: 1;
    	text-align: center;
    	line-height: 40px;
    	border-top: 1px solid #eee;
    	border-bottom: 1px solid #eee;
    }
    
    h4{
    	text-align: center;
    }
    
    </style>
    

      好记性不如破电脑,仅仅记录,怕忘了,不喜勿喷

  • 相关阅读:
    Bootstrap Table
    XML CDATA识别“<,>”
    LigerUI之Grid使用详解(一)——显示数据 --分页
    Oracle中对XMLType的简单操作(extract、extractvalue...)
    Qt实现应用程序单实例运行--LocalServer方式
    Live m3u8播放3个文件自动停止问题
    markdown
    node.js 知识记录
    .NET 高级架构师 WEB架构师 ------时间 总结 专注
    .NET 高级架构师 WEB架构师 ------走正确的路
  • 原文地址:https://www.cnblogs.com/qq735675958/p/8550874.html
Copyright © 2011-2022 走看看