提交 d4632f07 编写于 作者: D DCloud_LXH

feat: 调整示例展示

上级 38c584d3
...@@ -201,7 +201,6 @@ ...@@ -201,7 +201,6 @@
"navigationBarTitleText": "v-pre" "navigationBarTitleText": "v-pre"
} }
}, },
// #ifdef APP
{ {
"path": "pages/directive/v-once/v-once-options", "path": "pages/directive/v-once/v-once-options",
"style": { "style": {
...@@ -226,7 +225,6 @@ ...@@ -226,7 +225,6 @@
"navigationBarTitleText": "v-memo 组合式 API" "navigationBarTitleText": "v-memo 组合式 API"
} }
}, },
// #endif
// #ifdef WEB // #ifdef WEB
{ {
"path": "pages/directive/v-text/v-text-options", "path": "pages/directive/v-text/v-text-options",
......
<template> <template>
<view class="mt-10" ref="mixin-comp-root"> <view class="mt-10" ref="mixin-comp-root">
<text class="bold">Comp1:</text> <text class="bold">Comp1: inheritAttrs: false</text>
<text class="mt-10" <text class="mt-10" style="color:#ccc;"
>inheritAttrs: false, rootElementTitle should be null</text >rootElementTitle should be null</text
> >
<text class="mt-10 root-element-title-1">rootElementTitle: {{ rootElementTitle }}</text> <text class="mt-10 root-element-title-1">rootElementTitle: {{ rootElementTitle }}</text>
<!-- #ifdef APP -->
<text class="mt-10 bold">trigger emitter:</text> <text class="mt-10 bold">trigger emitter:</text>
<button class="mt-10 global-mixin-emit-1" @click="triggerEmitter('globalMixinEmit1')"> <button class="mt-10 global-mixin-emit-1" @click="triggerEmitter('globalMixinEmit1')">
trigger globalMixinEmit1 trigger globalMixinEmit1
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
trigger childMixinEmit trigger childMixinEmit
</button> </button>
<MixinComp /> <MixinComp />
<!-- #endif -->
</view> </view>
</template> </template>
...@@ -48,7 +50,7 @@ export default { ...@@ -48,7 +50,7 @@ export default {
}, },
mounted(){ mounted(){
const rootElement = this.$refs['mixin-comp-root'] as UniElement const rootElement = this.$refs['mixin-comp-root'] as UniElement
this.rootElementTitle = rootElement.getAttribute('title') this.rootElementTitle = JSON.stringify(rootElement.getAttribute('title'))
}, },
methods: { methods: {
triggerEmitter(emit: string){ triggerEmitter(emit: string){
......
<template> <template>
<view class="mt-10" ref="mixin-comp-root"> <view class="mt-10" ref="mixin-comp-root">
<text class="bold">Comp2:</text> <text class="bold">Comp2: inheritAttrs: true</text>
<text class="mt-10" <text class="mt-10" style="color:#ccc;">rootElementTitle should not be null</text >
>inheritAttrs: true, rootElementTitle should not be null</text
>
<text class="mt-10 root-element-title-2" <text class="mt-10 root-element-title-2"
>rootElementTitle: {{ rootElementTitle }}</text >rootElementTitle: {{ rootElementTitle }}</text
> >
...@@ -49,7 +47,7 @@ export default { ...@@ -49,7 +47,7 @@ export default {
}, },
mounted(){ mounted(){
const rootElement = this.$refs['mixin-comp-root'] as UniElement const rootElement = this.$refs['mixin-comp-root'] as UniElement
this.rootElementTitle = rootElement.getAttribute('title') this.rootElementTitle = JSON.stringify(rootElement.getAttribute('title'))
}, },
watch: { watch: {
globalMixinOnloadMsg1(newVal: string) { globalMixinOnloadMsg1(newVal: string) {
......
...@@ -7,6 +7,17 @@ ...@@ -7,6 +7,17 @@
<text id="mixin-data-msg" class="mb-10">mixinDataMsg: {{mixinDataMsg}}</text> <text id="mixin-data-msg" class="mb-10">mixinDataMsg: {{mixinDataMsg}}</text>
<text id="mixin-onload-msg" class="mb-10">mixinOnloadMsg: {{mixinOnloadMsg}}</text> <text id="mixin-onload-msg" class="mb-10">mixinOnloadMsg: {{mixinOnloadMsg}}</text>
<text id="mixin-computed" class="mb-10">mixinComputed: {{mixinComputed}}</text> <text id="mixin-computed" class="mb-10">mixinComputed: {{mixinComputed}}</text>
<Comp1 title="title" @globalMixinEmit1="(arg: string) => handleMixinEmitter('globalMixinEmit1', arg)"
@globalChildMixinEmit1="(arg: string) => handleMixinEmitter('globalChildMixinEmit1', arg)"
@globalMixinEmit2="(arg: string) => handleMixinEmitter('globalMixinEmit2', arg)"
@globalChildMixinEmit2="(arg: string) => handleMixinEmitter('globalChildMixinEmit2', arg)"
@mixinEmit="(arg: string) => handleMixinEmitter('mixinEmit', arg)"
@childMixinEmit="(arg: string) => handleMixinEmitter('childMixinEmit', arg)" />
<text v-if="handleMixinEmitterMsg" class="mt-10 handle-mixin-emitter-msg">
handleMixinEmitterMsg: {{ handleMixinEmitterMsg }}
</text>
<Comp2 class='comp2' title="title" />
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -14,7 +25,13 @@ ...@@ -14,7 +25,13 @@
</template> </template>
<script lang="uts"> <script lang="uts">
import Comp1 from './components/Comp1.uvue'
import Comp2 from './components/Comp2.uvue'
export default { export default {
components: {
Comp1,
Comp2,
},
mixins: [defineMixin({ mixins: [defineMixin({
props: { props: {
mixinProp: { mixinProp: {
...@@ -24,12 +41,13 @@ ...@@ -24,12 +41,13 @@
}, },
data() { data() {
return { return {
handleMixinEmitterMsg: '',
mixinDataMsg: '通过字面量定义非全局 mixin data', mixinDataMsg: '通过字面量定义非全局 mixin data',
mixinOnloadMsg: '' mixinOnloadMsg: ''
} }
}, },
computed: { computed: {
mixinComputed() : string { mixinComputed(): string {
const res = `通过字面量定义非全局 mixin computed, 更新后的 mixinOnloadMsg: ${this.mixinOnloadMsg}` const res = `通过字面量定义非全局 mixin computed, 更新后的 mixinOnloadMsg: ${this.mixinOnloadMsg}`
console.log(res) console.log(res)
return res return res
...@@ -39,10 +57,14 @@ ...@@ -39,10 +57,14 @@
this.mixinOnloadMsg = 'mixin onLoad msg in onLoad' this.mixinOnloadMsg = 'mixin onLoad msg in onLoad'
}, },
methods: { methods: {
mixinMethod() : string { mixinMethod(): string {
const res = '通过字面量定义非全局 mixin method' const res = '通过字面量定义非全局 mixin method'
console.log(res) console.log(res)
return res return res
},
handleMixinEmitter(emit: string, arg: string) {
this.handleMixinEmitterMsg = `触发 ${emit}, 参数为 ${arg}`
console.log(this.handleMixinEmitterMsg)
} }
}, },
})] })]
......
...@@ -25,5 +25,11 @@ ...@@ -25,5 +25,11 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
defineProps(['str', 'num', 'bool', 'obj', 'arr']) const props = defineProps(['str', 'num', 'bool', 'obj', 'arr'])
console.log('props.str: ',props.str);
console.log('props.num: ',props.num);
console.log('props.obj: ',props.obj);
console.log('props.bool: ',props.bool);
console.log('props.arr: ',props.arr);
</script> </script>
...@@ -27,5 +27,13 @@ ...@@ -27,5 +27,13 @@
<script lang="uts"> <script lang="uts">
export default { export default {
props: ['str', 'num', 'bool', 'obj', 'arr'], props: ['str', 'num', 'bool', 'obj', 'arr'],
mounted() {
console.log('this.$props is Map', this.$props, this.$props instanceof Map);
console.log('this.$props.str: ',this.$props['str']);
console.log('this.$props.num: ',this.$props['num']);
console.log('this.$props.bool: ',this.$props['bool']);
console.log('this.$props.arr: ',this.$props['arr']);
console.log('this.$props.obj: ',this.$props['obj']);
}
}; };
</script> </script>
<template> <template>
<view class="page"> <view class="page">
<!-- v-bind attribute --> <!-- v-bind attribute -->
<button id="disabled-btn" class="mb-10" :disabled="true"> <button id="disabled-btn" class="mb-10" :disabled="true">:disabled true</button>
:disabled true <button id="v-bind-disabled-btn" class="mb-10" v-bind:disabled="false">v-bind:disabled false</button>
</button>
<button id="v-bind-disabled-btn" class="mb-10" v-bind:disabled="false">
v-bind:disabled false
</button>
<!-- v-bind style --> <!-- v-bind style -->
<view class="flex justify-between flex-row mb-10"> <view class="flex justify-between flex-row mb-10">
...@@ -22,7 +18,7 @@ ...@@ -22,7 +18,7 @@
</view> </view>
<!-- v-bind props --> <!-- v-bind props -->
<Foo :title="dataInfo.fooProps.title" :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" /> <Foo :title :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" />
<!-- v-bind in style --> <!-- v-bind in style -->
<!-- #ifdef WEB --> <!-- #ifdef WEB -->
...@@ -32,51 +28,52 @@ ...@@ -32,51 +28,52 @@
</template> </template>
<script lang="uts"> <script lang="uts">
import Foo from './Foo-options.uvue' import Foo from './Foo-options.uvue'
type FooPropsObj = { type FooPropsObj = {
name : string name: string
} }
type FooProps = { type FooProps = {
title : string title: string
num : number num: number
obj : FooPropsObj obj: FooPropsObj
} }
type DataInfo = { type DataInfo = {
fontSize : string fontSize: string
backgroundColor : string backgroundColor: string
border : string border: string
fooProps : FooProps fooProps: FooProps
vBindClassBackgroundColor : string, vBindClassBackgroundColor: string
} }
export default { export default {
components: { Foo }, components: { Foo },
data() { data() {
return { return {
title: 'foo title',
dataInfo: { dataInfo: {
fontSize: '20px', fontSize: '20px',
backgroundColor: 'background-color: green', backgroundColor: 'background-color: green',
border: 'border: 2px solid red', border: 'border: 2px solid red',
fooProps: { fooProps: {
title: 'foo title', title: '',
num: 1, num: 1,
obj: { obj: {
name: 'foo obj name', name: 'foo obj name'
} }
}, },
vBindClassBackgroundColor: 'red', vBindClassBackgroundColor: 'red'
} as DataInfo } as DataInfo
} }
},
} }
}
</script> </script>
<style> <style>
/* #ifdef WEB */ /* #ifdef WEB */
.v-bind-css { .v-bind-css {
background-color: v-bind(dataInfo.vBindClassBackgroundColor); background-color: v-bind(dataInfo.vBindClassBackgroundColor);
height: 20px; height: 20px;
} }
/* #endif */ /* #endif */
</style> </style>
...@@ -725,18 +725,12 @@ export default { ...@@ -725,18 +725,12 @@ export default {
{ {
id: 'v-once-options', id: 'v-once-options',
name: 'v-once 选项式 API', name: 'v-once 选项式 API',
url: 'v-once-options', url: 'v-once-options'
// #ifdef WEB
enable: false
// #endif
}, },
{ {
id: 'v-once-composition', id: 'v-once-composition',
name: 'v-once 组合式 API', name: 'v-once 组合式 API',
url: 'v-once-composition', url: 'v-once-composition'
// #ifdef WEB
enable: false
// #endif
}, },
] ]
}, },
...@@ -747,18 +741,12 @@ export default { ...@@ -747,18 +741,12 @@ export default {
{ {
id: 'v-memo-options', id: 'v-memo-options',
name: 'v-memo 选项式 API', name: 'v-memo 选项式 API',
url: 'v-memo-options', url: 'v-memo-options'
// #ifdef WEB
enable: false
// #endif
}, },
{ {
id: 'v-memo-composition', id: 'v-memo-composition',
name: 'v-memo 组合式 API', name: 'v-memo 组合式 API',
url: 'v-memo-composition', url: 'v-memo-composition'
// #ifdef WEB
enable: false
// #endif
}, },
] ]
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册