-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (55 loc) · 1.15 KB
/
index.js
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
import Base from './Base'
import isQueriesEqual from './isQueriesEqual'
const kErrMsg = '<vue-Container-query> can only render' +
' one, and exactly one child component'
export const ContainerQuery = {
name: 'vue-container-query',
mixins: [Base],
model: { event: 'change' },
props: {
initialSize: {
type: Object
},
query: {
required: true,
type: Object
}
},
methods: {
handleChange (params) {
this.$emit('change', params)
}
},
watch: {
query: {
deep: true,
immediate: true,
handler (newVal, oldVal) {
if (this.cqCore && !isQueriesEqual(oldVal, newVal)) {
this.disposeObserver()
this.startObserving(newVal)
}
}
}
},
render () {
const slot = this.$slots.default
if (slot && slot.length === 1) {
return slot[0]
}
throw new Error(kErrMsg)
}
}
export function createContainerQueryMixin (query, initialSize) {
return {
mixins: [Base],
data () {
return { query, initialSize, containerQuery: {} }
},
methods: {
handleChange (params) {
this.containerQuery = params
}
}
}
}