提交 ab8dd6b7 编写于 作者: 雪洛's avatar 雪洛

feat: 调整代码支持web端

上级 b11a004b
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
return { return {
height: 0, height: 0,
is_open: this.open as boolean, is_open: this.open as boolean,
boxNode: null as Element | null, boxNode: null as UniElement | null,
contentNode: null as Element | null, contentNode: null as UniElement | null,
}; };
}, },
watch: { watch: {
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
$dispatch(this, 'UniCollapse', 'init', this) $dispatch(this, 'UniCollapse', 'init', this)
}, },
mounted() { mounted() {
this.boxNode = this.$refs['boxRef'] as Element; this.boxNode = this.$refs['boxRef'] as UniElement;
this.contentNode = this.$refs['contentRef'] as Element; this.contentNode = this.$refs['contentRef'] as UniElement;
// this.openCollapse(this.open) // this.openCollapse(this.open)
}, },
methods: { methods: {
......
...@@ -331,6 +331,7 @@ ...@@ -331,6 +331,7 @@
"navigationBarTitleText": "render function" "navigationBarTitleText": "render function"
} }
}, },
// #ifdef APP
{ {
"path": "pages/composition/mixins/mixins", "path": "pages/composition/mixins/mixins",
"style": { "style": {
...@@ -343,6 +344,7 @@ ...@@ -343,6 +344,7 @@
"navigationBarTitleText": "mixins-page-2" "navigationBarTitleText": "mixins-page-2"
} }
}, },
// #endif
{ {
"path": "pages/composition/provide/provide", "path": "pages/composition/provide/provide",
"style": { "style": {
...@@ -493,12 +495,14 @@ ...@@ -493,12 +495,14 @@
"navigationBarTitleText": "toRef" "navigationBarTitleText": "toRef"
} }
}, },
// #ifdef APP
{ {
"path": "pages/composition-api/reactivity/to-value/to-value", "path": "pages/composition-api/reactivity/to-value/to-value",
"style": { "style": {
"navigationBarTitleText": "toValue" "navigationBarTitleText": "toValue"
} }
}, },
// #endif
{ {
"path": "pages/composition-api/reactivity/to-refs/to-refs", "path": "pages/composition-api/reactivity/to-refs/to-refs",
"style": { "style": {
...@@ -584,7 +588,6 @@ ...@@ -584,7 +588,6 @@
} }
} }
], ],
// #ifdef APP
"tabBar": { "tabBar": {
"color": "#7A7E83", "color": "#7A7E83",
"selectedColor": "#007AFF", "selectedColor": "#007AFF",
...@@ -601,7 +604,6 @@ ...@@ -601,7 +604,6 @@
} }
] ]
}, },
// #endif
"globalStyle": { "globalStyle": {
"pageOrientation": "portrait", "pageOrientation": "portrait",
"navigationBarTitleText": "Hello UVUE", "navigationBarTitleText": "Hello UVUE",
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
} }
}, },
onReady() { onReady() {
// 通过组件 ref 属性获取组件实例, Uni组件名(驼峰)Element // 通过组件 ref 属性获取组件实例, Uni组件名(驼峰)UniElement
this.$slider1 = this.$refs['slider1'] as UniSliderElement; this.$slider1 = this.$refs['slider1'] as UniSliderElement;
}, },
methods: { methods: {
......
...@@ -20,7 +20,7 @@ export default { ...@@ -20,7 +20,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.name = this.$options.name this.name = this.$options.name!
}, },
methods: { methods: {
// getCustomKey (): string { // getCustomKey (): string {
......
...@@ -34,9 +34,11 @@ ...@@ -34,9 +34,11 @@
data.arr.push('d') data.arr.push('d')
} }
// #ifdef APP
const updateReadonlyData = () => { const updateReadonlyData = () => {
readonlyData.str = 'new readonly str' readonlyData.str = 'new readonly str'
readonlyData.num++ readonlyData.num++
readonlyData.arr.push('e') readonlyData.arr.push('e')
} }
// #endif
</script> </script>
\ No newline at end of file
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
} as StateNested } as StateNested
} as State) } as State)
// #ifdef APP
const incrementStateCount = () => { const incrementStateCount = () => {
state.count++ state.count++
} }
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
const incrementStateNestedCount = () => { const incrementStateNestedCount = () => {
state.nested.count++ state.nested.count++
} }
// #endif
const updatePageRender = () => { const updatePageRender = () => {
pageKey.value = Date.now() pageKey.value = Date.now()
......
...@@ -43,16 +43,16 @@ ...@@ -43,16 +43,16 @@
arr : number[] arr : number[]
} }
const countRef = ref(null) const countRef = ref<UniElement | null>(null)
const count = ref(0) const count = ref(0)
const watchCountRes = ref('') const watchCountRes = ref('')
const watchCountCleanupRes = ref('') const watchCountCleanupRes = ref('')
const watchCountTrackNum = ref(0) const watchCountTrackNum = ref(0)
const watchCountTriggerNum = ref(0) const watchCountTriggerNum = ref(0)
const stopWatchCount = watchEffect((onCleanup : OnCleanup) => { const stopWatchCount = watchEffect((onCleanup: OnCleanup) => {
if (countRef.value !== null) { if (countRef.value !== null) {
watchCountRes.value = `count: ${count.value}, count ref text (flush sync): ${(countRef.value as Element).getAttribute('value')}` watchCountRes.value = `count: ${count.value}, count ref text (flush sync): ${(countRef.value as UniElement).getAttribute('value')}`
} else { } else {
watchCountRes.value = `count: ${count.value}, count ref text (flush sync): ` watchCountRes.value = `count: ${count.value}, count ref text (flush sync): `
} }
...@@ -95,11 +95,11 @@ ...@@ -95,11 +95,11 @@
watchObjRes.value = `obj: ${JSON.stringify(obj)}` watchObjRes.value = `obj: ${JSON.stringify(obj)}`
}) })
const objStrRef = ref(null) const objStrRef = ref<UniElement | null>(null)
const watchObjStrRes = ref('') const watchObjStrRes = ref('')
watchEffect(() => { watchEffect(() => {
if (objStrRef.value !== null) { if (objStrRef.value !== null) {
watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): ${(objStrRef.value as Element).getAttribute('value')}` watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): ${(objStrRef.value as UniElement).getAttribute('value')}`
} else { } else {
watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): ` watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): `
} }
...@@ -108,11 +108,11 @@ ...@@ -108,11 +108,11 @@
flush: 'pre', flush: 'pre',
}) })
const objBoolRef = ref(null) const objBoolRef = ref<UniElement | null>(null)
const watchObjBoolRes = ref('') const watchObjBoolRes = ref('')
watchEffect(() => { watchEffect(() => {
if (objBoolRef.value !== null) { if (objBoolRef.value !== null) {
watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): ${(objBoolRef.value as Element).getAttribute('value')}` watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): ${(objBoolRef.value as UniElement).getAttribute('value')}`
} else { } else {
watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): ` watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): `
} }
......
...@@ -43,15 +43,15 @@ ...@@ -43,15 +43,15 @@
arr : number[] arr : number[]
} }
const countRef = ref(null) const countRef = ref<UniElement | null>(null)
const count = ref(0) const count = ref(0)
const watchCountRes = ref('') const watchCountRes = ref('')
const watchCountCleanupRes = ref('') const watchCountCleanupRes = ref('')
const watchCountTrackNum = ref(0) const watchCountTrackNum = ref(0)
const watchCountTriggerNum = ref(0) const watchCountTriggerNum = ref(0)
const stopWatchCount = watch(count, (count : number, prevCount : number, onCleanup : OnCleanup) => { const stopWatchCount = watch(count, (count : number, prevCount : number, onCleanup: OnCleanup) => {
watchCountRes.value = `count: ${count}, prevCount: ${prevCount}, count ref text (flush sync): ${(countRef.value as Element).getAttribute('value')}` watchCountRes.value = `count: ${count}, prevCount: ${prevCount}, count ref text (flush sync): ${(countRef.value as UniElement).getAttribute('value')}`
const cancel = () => { const cancel = () => {
watchCountCleanupRes.value = `watch count cleanup: ${count}` watchCountCleanupRes.value = `watch count cleanup: ${count}`
} }
...@@ -88,23 +88,23 @@ ...@@ -88,23 +88,23 @@
// immediate: true 第一次触发, 旧值应该是 undefined, 现在 app 是初始值 // immediate: true 第一次触发, 旧值应该是 undefined, 现在 app 是初始值
const watchObjRes = ref('') const watchObjRes = ref('')
watch(obj, (obj : Obj, prevObj : Obj) => { watch(obj, (obj : Obj, prevObj ?: Obj) => {
watchObjRes.value = `obj: ${JSON.stringify(obj)}, prevObj: ${JSON.stringify(prevObj)}` watchObjRes.value = `obj: ${JSON.stringify(obj)}, prevObj: ${JSON.stringify(prevObj)}`
}, { immediate: true }) }, { immediate: true })
const objStrRef = ref(null) const objStrRef = ref<UniElement | null>(null)
const watchObjStrRes = ref('') const watchObjStrRes = ref('')
watch(() : string => obj.str, (str : string, prevStr : string) => { watch(() : string => obj.str, (str : string, prevStr : string) => {
watchObjStrRes.value = `str: ${str}, prevStr: ${prevStr}, obj.str ref text (flush pre): ${(objStrRef.value as Element).getAttribute('value')}` watchObjStrRes.value = `str: ${str}, prevStr: ${prevStr}, obj.str ref text (flush pre): ${(objStrRef.value as UniElement).getAttribute('value')}`
}, { }, {
// 侦听器在组件渲染之前触发 // 侦听器在组件渲染之前触发
flush: 'pre', flush: 'pre',
}) })
const objBoolRef = ref(null) const objBoolRef = ref<UniElement | null>(null)
const watchObjBoolRes = ref('') const watchObjBoolRes = ref('')
watch(() : boolean => obj.bool, (bool : boolean, prevBool : boolean) => { watch(() : boolean => obj.bool, (bool : boolean, prevBool : boolean) => {
watchObjBoolRes.value = `bool: ${bool}, prevBool: ${prevBool}, obj.bool ref text (flush post): ${(objBoolRef.value as Element).getAttribute('value')}` watchObjBoolRes.value = `bool: ${bool}, prevBool: ${prevBool}, obj.bool ref text (flush post): ${(objBoolRef.value as UniElement).getAttribute('value')}`
}, { }, {
// 侦听器延迟到组件渲染之后触发 // 侦听器延迟到组件渲染之后触发
flush: 'post' flush: 'post'
......
...@@ -47,7 +47,7 @@ export default { ...@@ -47,7 +47,7 @@ export default {
} }
}, },
mounted(){ mounted(){
const rootElement = this.$refs['mixin-comp-root'] as Element const rootElement = this.$refs['mixin-comp-root'] as UniElement
this.rootElementTitle = rootElement.getAttribute('title') this.rootElementTitle = rootElement.getAttribute('title')
}, },
methods: { methods: {
......
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
} }
}, },
mounted(){ mounted(){
const rootElement = this.$refs['mixin-comp-root'] as Element const rootElement = this.$refs['mixin-comp-root'] as UniElement
this.rootElementTitle = rootElement.getAttribute('title') this.rootElementTitle = rootElement.getAttribute('title')
}, },
watch: { watch: {
......
...@@ -146,7 +146,11 @@ ...@@ -146,7 +146,11 @@
{ {
name: 'toValue', name: 'toValue',
url: 'to-value', url: 'to-value',
// #ifdef APP
enable: true, enable: true,
// #else
enable: false,
// #endif
}, },
{ {
name: 'toRefs', name: 'toRefs',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册