zoukankan      html  css  js  c++  java
  • todo-list 个人练习

    总结:

    a:父组件向子组件传值  用  props

    b:子组件向父组件传值  用 this.$emit('handle',arg)

    部分页面代码:

    1、app.vue代码

    <template>
    	<div id="app">
    		<img src="./assets/logo.png">
    		<div class="box">
    			<input type="text" v-model="inputvalue" @keydown.13="insertInput" placeholder="请输入待办事项">
    			<button @click="insertInput">提交</button>
    		</div>
    		<ul class="todolist">
    			<todo-item v-for="(item,index) of list" :key="index" :index="index" :content="item" @deleteitem="deleteItem">{{ item }}</todo-item>
    		</ul>
    
    	</div>
    </template>
    <script>
    	import HelloWorld from './components/HelloWorld'
    
    	export default {
    		components: {
    			'todo-item': HelloWorld,
    			'car':car
    		},
    		data: function() {
    			return {
    				inputvalue: '', //数据绑定
    				list: []        //数据列表
    			}
    		},
    		methods: {
    			insertInput: function() {
    				if (this.inputvalue) {
    					this.list.push(this.inputvalue);
    					this.inputvalue = '';
    				}
    			},
    			deleteItem: function(index) {
    				this.list.splice(index, 1);
    			}
    		}
    	}
    </script>
    
    <style>
    	#app {
    		font-family: 'Avenir', Helvetica, Arial, sans-serif;
    		-webkit-font-smoothing: antialiased;
    		-moz-osx-font-smoothing: grayscale;
    		/* text-align: center; */
    		color: #2c3e50;
    		/* margin-top: 60px; */
    	}
    
    	.box {
    		display: flex;
    		flex-direction: row;
    	}
    
    	.todolist {
    		list-style: none;
    		padding: 0;
    		margin: 0;
    		padding-top: 30px;
    		 300px;
    	}
    </style>
    

     2、helloWorld.vue代码

    <template>
        <li  @click="deletehandle">{{content}}</li>
    </template>
    
    <script>
    export default {
      props:['content','index'],
    	methods:{
    		deletehandle:function(){
    			this.$emit('deleteitem',this.index)
    		}
    	}
     
    }
    </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 {
      /* display: inline-block; */
      margin: 0 10px;
    	/* text-align: left; */
    }
    a {
      color: #42b983;
    }
    </style>
    
  • 相关阅读:
    IP查询网和traceroute找到的网络出口不一致的原因
    [转载] 深入理解VMware虚拟机网络通信原理
    https工作流程
    HTTP1.1协议-RFC2616-中文版
    条件变量调用Signal的时候是否需要持有mutex
    HTTP Get一定是幂等的吗,统计访问量的时候呢?
    unix网络编程
    MySQL-SQL基础-DCL
    MySQL-SQL基础-查询1
    MySQL-SQL基础-子查询
  • 原文地址:https://www.cnblogs.com/zhaoliu100125/p/10042785.html
Copyright © 2011-2022 走看看