批改状态:合格
老师批语:知道vue是什么, 能做什么?怎么用, 差不多就知道了核心了,下一步就是不断的补充知识点, 做加法就可以了
实例演示vue中的常用属性,如计算属性,过滤器,侦听器等

<body><div class="app"><p>{{words}}</p><p v-html="site"></p><p>{{code}}</p><p v-html="name"></p><p>30 + 40 = {{30 + 40}}</p><p>{{true ? '不爽': '棒棒'}}</p><!-- 直接输出字符串 --><p>{{'Zhang Fugen'.split('').reverse().join('')}}</p></div><script>const vm = new Vue({el: ".app",data: {site: "Hello <strong style='color:red'>zhangfugen.cn</strong>",name: "<strong>张福根</strong>",},});</script>

<body><div class="app"><p>{{words.split('').reverse().join('') }}</p><p>{{sites | wordsToCase |substring}}</p></div><script>const vm = new Vue({el: ".app",data: {words: "ABCDEF",sites: "zhangfugen.cn",},// 计算属性,computed: {reverseWords() {return this.words.split("").reverse().join("");},},// 过滤器属性filters: {wordsToCase(str) {return str.toUpperCase();},substring(str) {return str.substr(2, 5);},},});</script></body>

<body><p>小小加法器</p><div class="app"><!-- v-model: 双向数据绑定 --><input type="number" v-model="add1" name="" id="" /> +<input type="number" v-model="add2" name="" id="" /> =<span>{{counts}}</span><script>const vm = new Vue({el: ".app",data: {add1: 0,add2: 0,counts: 0,},// 方法methods: {add(x, y) {this.counts = x * 1 + y * 1;},},// 侦听器属性watch: {add1(newVal) {this.add(newVal, this.add2);},add2(newVal) {this.add(newVal, this.add1);},},});console.log(vm.add1);</script></div></body>

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号