Vue -基础知识
Vue实例:Vue 思想是以数据为中心。
el:代表接管DOM节点
data:代表Vue 变量;
methods : 代表Vue方法;
v 开头的代表Vue指令,后面内容是 JS 表达式
事件绑定:v-on:click='handleclick' 简写 @click='handleclick'
属性绑定:v-bind:title='hello world {{content}}' 简写 :title='hello world {{content}}' 后面是 JS表达式
计算属性:

侦听器:

v-if 是剔除对应标签、 v-show 是通过css 隐藏标签
循环指令 v-for

Vue组件也是实例,父组件向子组件传递数据采用属性的形式,子组件通过发布事件方式向父组件传递数据;
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="root">
<input v-model="inputValue"/>
<button @click="handleSubmit">提交</button>
<ul>
<todo-item
v-for="(item,index) of list"
:key="index"
:content="item"
:index="index"
@delete="handleDelete">
</todo-item>
</ul>
</div>
<script type="text/javascript">
Vue.component('todo-item',{
props:['content','index'],
template:'<li @click="handleClick">{{content}}</li>',
methods:{
handleClick:function(){
this.$emit('delete',this.index)
}
}
});
var app = new Vue({
el:'#root',
data :{
inputValue:'',
list:[]
},
methods:{
handleSubmit:function(){
this.list.push(this.inputValue),
this.inputValue=''
},
handleDelete:function(index){
this.list.splice(index,1);
}
}
});
</script>
</body>
</html>
xx
posted on 2021-04-27 14:06 TrustNature 阅读(82) 评论(0) 收藏 举报
浙公网安备 33010602011771号