banner-h5.vue
1.44 KB
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
67
<template>
<div>
<Input :value="title" @input="onUpdateTitle" placeholder="标题"/>
<Input :value="link" @input="onUpdateLink" placeholder="链接"/>
</div>
</template>
<script>
import util from '@/libs/util'
export default {
props: ['value'],
data() {
const qsObj = util.qsParse(this.value);
delete qsObj.title
return {
title: util.getUrlQueryString(this.value, 'title'),
link: util.getLink(this.value) + (util.isObjectEmpty(qsObj) ? '': '?' + util.qsStringify(qsObj)),
qsObj
};
},
watch: {
value(newVal) {
console.log('newVal:', newVal);
this.updateValue(newVal);
}
},
methods: {
onUpdateTitle(val) {
this.title = val;
this.$emit('input', this.getUrl());
},
onUpdateLink(val) {
const qsObj = util.qsParse(val);
this.link = val;
this.qsObj = qsObj;
console.log('link=>', this.link)
this.$emit('input', this.getUrl());
},
getUrl() {
return `${util.getLink(this.link)}?title=${this.title}${ util.isObjectEmpty(this.qsObj) ? '': '&' + util.qsStringify(this.qsObj)}`;
},
updateValue(url) {
console.log('updatevalue=>', url);
const qsObj = util.qsParse(url);
this.title = qsObj.title || '';
delete qsObj.title;
this.link = util.getLink(url) + (util.isObjectEmpty(qsObj) ? '': '?' + util.qsStringify(qsObj));
this.qsObj = qsObj;
}
}
}
</script>
<style>
</style>