Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
6971e295
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6971e295
编写于
7月 09, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(component): is 补充内置组件示例
上级
b02fc844
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
129 addition
and
119 deletion
+129
-119
pages/built-in/special-elements/component/component-composition.uvue
...-in/special-elements/component/component-composition.uvue
+39
-43
pages/built-in/special-elements/component/component-options.uvue
...uilt-in/special-elements/component/component-options.uvue
+46
-43
pages/built-in/special-elements/component/component.test.js
pages/built-in/special-elements/component/component.test.js
+44
-33
未找到文件。
pages/built-in/special-elements/component/component-composition.uvue
浏览文件 @
6971e295
<template>
<template>
<view class="container">
<view class="container">
<component :is="currentComponentStr" />
<component :is="currentComponentInstance" />
<component :is="currentComponentInstance" />
<component :is="myInput" :value="inputValue" id="my-input" />
<button @click="changeCurrentComponent">change current component</button>
<button @click="changeCurrentComponent">change current component</button>
</view>
</view>
</template>
</template>
<script lang="uts">
<script setup lang="uts">
import Foo from '../../../../components/Foo.uvue'
import Foo from '../../../../components/Foo.uvue'
import Bar from '../../../../components/Bar.uvue'
import Bar from '../../../../components/Bar.uvue'
export default {
components: {
const currentComponentStr = ref('Foo')
Foo,
const currentComponentInstance = ref(Foo)
Bar
const myInput = ref('input')
},
const inputValue = ref('default value')
data() {
return {
const changeCurrentComponent = () => {
currentComponentStr: 'Foo',
if (currentComponentStr.value === 'Foo') {
currentComponentInstance: Foo
currentComponentStr.value = 'Bar'
}
currentComponentInstance.value = Bar
},
} else {
methods: {
currentComponentStr.value = 'Foo'
changeCurrentComponent() {
currentComponentInstance.value = Foo
if (this.currentComponentStr === 'Foo') {
}
this.currentComponentStr = 'Bar'
}
this.currentComponentInstance = Bar
} else {
defineExpose({
this.currentComponentStr = 'Foo'
changeCurrentComponent
this.currentComponentInstance = Foo
})
}
</script>
}
}
<style>
}
.item {
</script>
display: flex;
flex-direction: row;
<style>
margin: 15px;
.item {
border: #eee solid 1px;
display: flex;
}
flex-direction: row;
margin: 15px;
border: #eee solid 1px;
}
</style>
</style>
\ No newline at end of file
pages/built-in/special-elements/component/component-options.uvue
浏览文件 @
6971e295
<template>
<template>
<view class="container">
<view class="container">
<component :is="currentComponentStr" />
<component :is="currentComponentStr" />
<component :is="currentComponentInstance" />
<component :is="currentComponentInstance" />
<button @click="changeCurrentComponent">change current component</button>
<component :is="myInput" :value="inputValue" id="my-input" />
</view>
<button @click="changeCurrentComponent">change current component</button>
</template>
</view>
</template>
<script lang="uts">
import Foo from '../../../../components/Foo.uvue'
<script lang="uts">
import Bar from '../../../../components/Bar.uvue'
import Foo from '../../../../components/Foo.uvue'
export default {
import Bar from '../../../../components/Bar.uvue'
components: {
export default {
Foo,
components: {
Bar
Foo,
},
Bar
data() {
},
return {
data() {
currentComponentStr: 'Foo',
return {
currentComponentInstance: Foo
currentComponentStr: 'Foo',
}
currentComponentInstance: Foo,
},
myInput: 'input',
methods: {
inputValue: 'default value'
changeCurrentComponent() {
}
if (this.currentComponentStr === 'Foo') {
},
this.currentComponentStr = 'Bar'
methods: {
this.currentComponentInstance = Bar
changeCurrentComponent() {
} else {
if (this.currentComponentStr === 'Foo') {
this.currentComponentStr = 'Foo'
this.currentComponentStr = 'Bar'
this.currentComponentInstance = Foo
this.currentComponentInstance = Bar
}
} else {
}
this.currentComponentStr = 'Foo'
}
this.currentComponentInstance = Foo
}
}
</script>
}
}
<style>
}
.item {
</script>
display: flex;
flex-direction: row;
<style>
margin: 15px;
.item {
border: #eee solid 1px;
display: flex;
}
flex-direction: row;
margin: 15px;
border: #eee solid 1px;
}
</style>
</style>
\ No newline at end of file
pages/built-in/special-elements/component/component.test.js
浏览文件 @
6971e295
const
PAGE_OPTIONS
=
'
/pages/built-in/special-elements/component/component-options
'
const
PAGE_OPTIONS
=
'
/pages/built-in/special-elements/component/component-options
'
const
PAGE_COMPOSITION
=
'
/pages/built-in/special-elements/component/component-composition
'
const
PAGE_COMPOSITION
=
'
/pages/built-in/special-elements/component/component-composition
'
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
describe
(
'
built-in/component
'
,
()
=>
{
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
let
page
const
test
=
async
()
=>
{
describe
(
'
built-in/component
'
,
()
=>
{
await
page
.
waitFor
(
'
view
'
)
let
page
let
fooList
=
await
page
.
$$
(
'
.component-foo
'
)
const
test
=
async
(
pagePath
)
=>
{
expect
(
fooList
.
length
).
toBe
(
2
)
page
=
await
program
.
reLaunch
(
pagePath
)
expect
(
await
fooList
[
0
].
text
()).
toBe
(
'
this is component Foo
'
)
await
page
.
waitFor
(
'
view
'
)
expect
(
await
fooList
[
1
].
text
()).
toBe
(
'
this is component Foo
'
)
const
isOptionsPage
=
pagePath
.
indexOf
(
'
component-options
'
)
!==
-
1
let
fooList
=
await
page
.
$$
(
'
.component-foo
'
)
let
barList
=
await
page
.
$$
(
'
.component-bar
'
)
expect
(
fooList
.
length
).
toBe
(
isOptionsPage
?
2
:
1
)
expect
(
barList
.
length
).
toBe
(
0
)
expect
(
await
fooList
[
0
].
text
()).
toBe
(
'
this is component Foo
'
)
if
(
isOptionsPage
)
{
await
page
.
callMethod
(
'
changeCurrentComponent
'
)
expect
(
await
fooList
[
1
].
text
()).
toBe
(
'
this is component Foo
'
)
}
fooList
=
await
page
.
$$
(
'
.component-foo
'
)
expect
(
fooList
.
length
).
toBe
(
0
)
let
barList
=
await
page
.
$$
(
'
.component-bar
'
)
expect
(
barList
.
length
).
toBe
(
0
)
barList
=
await
page
.
$$
(
'
.component-bar
'
)
expect
(
barList
.
length
).
toBe
(
2
)
await
page
.
callMethod
(
'
changeCurrentComponent
'
)
expect
(
await
barList
[
0
].
text
()).
toBe
(
'
this is component Bar
'
)
expect
(
await
barList
[
1
].
text
()).
toBe
(
'
this is component Bar
'
)
fooList
=
await
page
.
$$
(
'
.component-foo
'
)
}
expect
(
fooList
.
length
).
toBe
(
0
)
it
(
'
component Options API
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_OPTIONS
)
barList
=
await
page
.
$$
(
'
.component-bar
'
)
await
test
()
expect
(
barList
.
length
).
toBe
(
isOptionsPage
?
2
:
1
)
})
expect
(
await
barList
[
0
].
text
()).
toBe
(
'
this is component Bar
'
)
it
(
'
component Composition API
'
,
async
()
=>
{
if
(
isOptionsPage
)
{
page
=
await
program
.
reLaunch
(
PAGE_COMPOSITION
)
expect
(
await
barList
[
1
].
text
()).
toBe
(
'
this is component Bar
'
)
await
test
()
}
})
// web 端自动化测试,无法获取非 uni 元素
if
(
!
isWeb
)
{
const
myInput
=
await
page
.
$
(
'
#my-input
'
)
expect
(
await
myInput
.
property
(
'
value
'
)).
toBe
(
'
default value
'
)
}
}
it
(
'
component Options API
'
,
async
()
=>
{
await
test
(
PAGE_OPTIONS
)
})
it
(
'
component Composition API
'
,
async
()
=>
{
await
test
(
PAGE_COMPOSITION
)
})
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录