1.问题:get 请求参数为数组时,自动添加了[],导致后台没有收到请求参数。

1
2
3
4
5
6
axios.get(url, {
params: {
tag: [1, 2, 3, 4],
},
});
// ...tag[]=1&tag[]=2&tag[]=3&tag[]=4
阅读全文 »


此问题是 chrome vue.js devtools 插件引起的。 我的插件版本号是: Vue.js devtools 6.5.0 操作系统:win7 解决办法: F12 打开调试控制台 -> 点击 Vue -> 点击右上角竖排三个点 -> 选择 Devtools plugins -> 点击控制台中间的 Vue2 -> 在最右侧 Plugin settings 开启 Legacy Actions 开关

阅读全文 »


下面这样写无法正确加载背景图片:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<template>
<div class="container"></div>
</template>

<script>
export default {
name: 'component'
}
</script>

<style scoped lang="scss">
.container {
height: 40px;
width: 40px;
background-image: url('@/assets/image.svg');
}
</style>
阅读全文 »


1.题目描述

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class EventEmitter {
constructor() {
// 创建一个空对象 events,用于存储事件名称和对应的回调函数数组
this.events = {};
}
// 接受两个参数,eventName 事件名称,callback 回调函数
subscribe(eventName, callback) {
// 如果 evnets 对象中不存在 eventName 对应的数组,则创建一个空数组
if (!this.events[eventName]) {
this.events[eventName] = [];
}

// 将回调函数添加到对应事件的数组中
this.events[eventName].push(callback);

// 返回一个包含 unsubscribe 方法的对象,以允许用户取消订阅
const unsubscribe = () => {
const index = this.events[eventName].indexOf(callback);
if (index !== -1) {
this.events[eventName].splice(index, 1);
}
};

return { unsubscribe };
}
// 接受两个参数,eventName 事件名称和可选的 args 参数数组
emit(eventName, args = []) {
// 首先检查 events 对象中是否存在 eventName 对应的数组,如果不存在则返回一个空数组
if (!this.events[eventName]) {
return [];
}

const results = [];
// 遍历 eventName 对应的数组,依次调用每个回调函数,并将 args 作为参数传递给它们
// 将每个回调函数的返回值添加到一个结果数组中
for (const callback of this.events[eventName]) {
results.push(callback(...args));
}
// 返回结果数组
return results;
}
}

// 示例用法
const emitter = new EventEmitter();

// 订阅事件 "myEvent"
const subscription1 = emitter.subscribe("myEvent", (arg1, arg2) => {
console.log(`Callback 1: ${arg1}, ${arg2}`);
});

// 另一个订阅同一个事件
const subscription2 = emitter.subscribe("myEvent", (arg1, arg2) => {
console.log(`Callback 2: ${arg1}, ${arg2}`);
});

// 触发事件 "myEvent",并传递参数
const results = emitter.emit("myEvent", ["Hello", "World"]);

console.log(results); // 输出结果数组

// 取消订阅第一个回调函数
subscription1.unsubscribe();

// 再次触发事件 "myEvent"
emitter.emit("myEvent", ["Goodbye", "EventEmitter"]);
阅读全文 »
0%