Ajax快速上手

什么是 Ajax?

XMLHttpRequest:该对象是对 JavaScript 的一个扩展,可使网页与服务器进行通讯,是创建 Ajax 应用的最佳选择。实际上把Ajax当成 XMLHttpRequest

阅读更多

v-model实现双向数据绑定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="vue">
<h4>{{msg}}</h4>
<label>
<input type="text" v-model="msg">
</label>
</div>
<script>
const vm = new Vue({
el: "#vue",
data: {
msg: "test"
},
methods: {}
});
</script>
</body>
</html>

Bootstrap栅栏结构

  • .container :容器

    • 屏幕<768px时,使用最大宽度(效果等同于container-full)
    • 768px≤屏幕<992px时,container的宽度为750px
    • 992px≤屏幕<1200px,container的宽度为970px
    • 1200px≤屏幕,container的宽度为1170px

    container左右各有15px的内边距

阅读更多

v-if和v-show

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>循环</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="vue">
<input type="submit" @click="show=!show">
<p v-if="show">这是使用v-if控制的语句</p>
<p v-show="show">这是使用v-show控制的语句</p>
</div>
<script>
const vm = new Vue({
el: "#vue",
data: {
show: true
},
methods: {
submit() {
this.listData.unshift({name: this.name, value: this.value})
}
}
});
</script>
</body>
</html>

区别:

  • v-if 每次都会重新删除、创建元素
  • v-show 每次隐藏只是使 display=none
  • v-if 切换耗费性能比 v-show 高(每次切换都重新渲染)
    • 当不显示组件的时候,v-show 初始渲染耗费性能比 v-show 高(v-if 不渲染,但是 v-show 渲染,只是设置 display=none)

建议:

如果组件涉及到频繁的切换,则使用v-show

如果组件几乎不会显示给用户看,那么使用v-if

事件修饰符

  • .stop : 阻止冒泡
  • .prevent : 阻止默认事件
  • .capture : 添加事件侦听器时使用事件捕获模式 => 即从外到里触发事件
  • .self : 只有事件在该元素本身(比如不是子元素)触发时回调 => 只有点击当前元素时才会触发函数,而不是通过冒泡
  • .once : 事件只触发一次 => 事件修饰符只触发一次
阅读更多

跑马灯效果展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>个人界面</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="text">
<input type="button" value="开始效果" :title="beginTitle" @click="begin">
<input type="button" value="停止效果" :title="endTitle" @click="ends">
<br>
{{msg}}
</div>
<script>
const vm = new Vue({
el: "#text",
data: {
msg: "跑马灯效果展示...",
beginTitle: "开始展示效果",
endTitle: "停止效果展示",
intervalID: null
},
methods: {
begin: function () {
/*
* 使用箭头函数,不需要考虑 this 问题
* 删除原来的 function ,在 function 后面的括号后面加上 => 即可改为箭头函数
* 设置定时器
*/
if (this.intervalID == null) {
this.intervalID = setInterval(() => {
this.msg = this.msg.substring(1) + this.msg.substring(0, 1);
}, 300);
}
},
/*可以简化函数*/
ends() {
/*停止定时器*/
clearInterval(this.intervalID);
this.intervalID = null;
this.msg = "跑马灯效果展示...";
}
}
})
;
</script>
</body>
</html>
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×