You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
# 笔记
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
1. 问题:
|
|
|
|
|
|
|
|
|
|
```vue
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<title>Title</title>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div id="app">
|
|
|
|
|
<counter :num="count" @incr="add" @decr="reduce"></counter>
|
|
|
|
|
</div>
|
|
|
|
|
<script src="node_modules/vue/dist/vue.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
//定义局部组件
|
|
|
|
|
const counter = {//声明自定义组件并设置其名称
|
|
|
|
|
template:`<div>
|
|
|
|
|
<button @click="handleAdd">+</button>
|
|
|
|
|
<button @click="handleReduce">-</button>
|
|
|
|
|
<h1>NUM:{{ num }}</h1>
|
|
|
|
|
</div>`,//自定义组件
|
|
|
|
|
props:['num'], //子组件接收title属性
|
|
|
|
|
methods: {
|
|
|
|
|
handleAdd(){
|
|
|
|
|
this.$emit('incr');
|
|
|
|
|
},
|
|
|
|
|
handleReduce(){
|
|
|
|
|
this.$emit("decr");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const app = new Vue({//(1)声明父级标签
|
|
|
|
|
el:"#app", //element ,vue 作用的标签
|
|
|
|
|
data:{
|
|
|
|
|
count: 0,//id为app的标签对应的数据
|
|
|
|
|
},
|
|
|
|
|
components:{//声明组件,在id为app的组件当中声明子组件,其子组件为introduce
|
|
|
|
|
counter
|
|
|
|
|
},
|
|
|
|
|
methods:{
|
|
|
|
|
add(){
|
|
|
|
|
this.count++;
|
|
|
|
|
},
|
|
|
|
|
reduce(){
|
|
|
|
|
this.count--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在这个代码中的NUM:{{ num }} 所表达的意思是什么呢?
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
将所提供的界面进行一个优化
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
制作界面
|