1 Star 0 Fork 0

铃酱是男生/js基础代码学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
computed&&watch.html 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
铃酱是男生 提交于 2022-06-28 02:46 . 第一次提交
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<input type="text" v-model="mytext">
<ul>
<li v-for="data in datalistcom" :key="data">
{{ data }}
</li>
</ul>
<div>------------------------</div>
<div>
<!-- <p>单价:<input type="text" v-model="price"></p>
<p>数量:<input type="text" v-model="number"></p>
<p>计算金额:{{sum}}</p> -->
<div>{{ number }}</div>
<button @click="add">+++</button>
</div>
</div>
<script src="http://static.runoob.com/assets/vue/1.0.11/vue.min.js"></script>
<script>
const vm = new Vue({
el: '#app',
data() {
return {
datalist: ["aaa", "bbb", "ccc", "ddd", "aa", "a", "cc", "dd"],
mytext: '',
price: 100,
number: 1,
sum: 0
}
},
watch: {
// price() {
// console.log(this.price)
// if (this.price * this.number < 1000 && this.price * this.number > 0) {
// this.sum = this.price * this.number + 100
// } else {
// this.sum = this.price * this.number
// }
// },
number(newVal,oldVal) {
console.log('newVal', newVal);
console.log('oldVal', oldVal);
// console.log(this.price)
// if (this.price * this.number < 1000 && this.price * this.number > 0) {
// this.sum = this.price * this.number + 100
// } else {
// this.sum = this.price * this.number
// }
}
},
computed: {
changeName() {
return this.name + '123'
},
datalistcom() {
return this.datalist.filter(item => item.indexOf(this.mytext) > -1)
}
},
methods: {
add () {
this.number ++;
}
},
})
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ling0512/js-basic-code-learning.git
git@gitee.com:ling0512/js-basic-code-learning.git
ling0512
js-basic-code-learning
js基础代码学习
master

搜索帮助