diff --git "a/\351\273\204\345\256\207\347\205\214/5.29 Vue\345\217\202\346\225\260.md" "b/\351\273\204\345\256\207\347\205\214/5.29 Vue\345\217\202\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..7d9b63585b73d3d8484dddf303fba8674909fc31 --- /dev/null +++ "b/\351\273\204\345\256\207\347\205\214/5.29 Vue\345\217\202\346\225\260.md" @@ -0,0 +1,122 @@ +# Vue + +## v-bind缩写 +``` + +... + + +... + + + ... +``` + +## v-on 缩写 +``` + +... + + +... + + + ... +``` + +## Vue动态参数 +在 DOM 中使用模板时 (直接在一个 HTML 文件里撰写模板),还需要避免使用大写字符来命名键名,因为浏览器会把 attribute 名全部强制转为小写: +``` + +
+ 现在todo是:{{todo}} +
+ +
+ +
+``` + +``` +// 后端代码 +let app = new Vue({ + el:"#app", + data() { + return { + url:"http:baidu.com", + count:0, + todo:"href", + todos:["href","http","show","what"] + } + }, + methods: { + btn:function(){ + let rnd = Math.floor(Math.random()*this.todos.length); + console.log(rnd); + return this.todo = this.todos[rnd],this.count+=1 + } + }, +}) +``` + +## 计算属性(computed) +对代码进行简单的运算 +``` + +
+

{{age}}岁的你出生在{{birth}}年

+

今天是这个月的第{{today}}天

+
+``` + +``` +// 后端代码 +let app = new Vue({ + el: "#app", + data() { + return { + age: 18, + day: 0 + } + }, + computed: { + birth: function () { + let date = new Date(); + let year = date.getFullYear(); + + return year - this.age; + }, + today: function () { + let date = new Date(); + let today = date.getDate(); + return this.day + today; + } + } +}) +``` + +## 监听属性(watch) +监听数据的变动 +``` + +
+

大家好,我是{{name}}

+
+``` + +``` +let app = new Vue({ + el: "#app", + data() { + return { + name: "李白" + } + }, + watch: { + name: function (newVal, oldVal) { + console.log("这是变化后的数据---" + newVal); + console.log("这是变化前的数据---" + oldVal); + } + } + }) +``` \ No newline at end of file