Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
caaca366
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看板
提交
caaca366
编写于
1月 24, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 补充 web 平台 mixin 示例
上级
2cd20c33
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
100 addition
and
6 deletion
+100
-6
pages.json
pages.json
+9
-1
pages/composition/mixins/mixins-web.test.js
pages/composition/mixins/mixins-web.test.js
+32
-0
pages/composition/mixins/mixins-web.uvue
pages/composition/mixins/mixins-web.uvue
+50
-0
pages/tab-bar/options-api.uvue
pages/tab-bar/options-api.uvue
+9
-5
未找到文件。
pages.json
浏览文件 @
caaca366
...
@@ -335,7 +335,7 @@
...
@@ -335,7 +335,7 @@
"navigationBarTitleText"
:
"render function"
"navigationBarTitleText"
:
"render function"
}
}
},
},
//
#ifdef
APP
//
#ifdef
APP
{
{
"path"
:
"pages/composition/mixins/mixins"
,
"path"
:
"pages/composition/mixins/mixins"
,
"style"
:
{
"style"
:
{
...
@@ -348,6 +348,14 @@
...
@@ -348,6 +348,14 @@
"navigationBarTitleText"
:
"mixins-page-2"
"navigationBarTitleText"
:
"mixins-page-2"
}
}
},
},
//
#endif
//
#ifdef
WEB
{
"path"
:
"pages/composition/mixins/mixins-web"
,
"style"
:
{
"navigationBarTitleText"
:
"mixins"
}
},
//
#endif
//
#endif
{
{
"path"
:
"pages/composition/provide/provide"
,
"path"
:
"pages/composition/provide/provide"
,
...
...
pages/composition/mixins/mixins-web.test.js
0 → 100644
浏览文件 @
caaca366
const
PAGE_PATH
=
'
/pages/composition/mixins/mixins-web
'
let
page
describe
(
'
mixins
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
// 该实例只针对 web 平台
it
(
'
android
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
// TODO: web 平台不支持 mixins 嵌套及对象字面量创建方式
// 暂时针对 web 平台只测试基本功能
it
(
'
basic
'
,
async
()
=>
{
const
mixinProp
=
await
page
.
$
(
'
#mixin-prop
'
)
expect
(
await
mixinProp
.
text
()).
toBe
(
'
mixinProp: 通过字面量定义非全局 mixin props
'
)
const
mixinDataMsg
=
await
page
.
$
(
'
#mixin-data-msg
'
)
expect
(
await
mixinDataMsg
.
text
()).
toBe
(
'
mixinDataMsg: 通过字面量定义非全局 mixin data
'
)
const
mixinOnloadMsg
=
await
page
.
$
(
'
#mixin-onload-msg
'
)
expect
(
await
mixinOnloadMsg
.
text
()).
toBe
(
'
mixinOnloadMsg: mixin onLoad msg in onLoad
'
)
const
mixinComputed
=
await
page
.
$
(
'
#mixin-computed
'
)
expect
(
await
mixinComputed
.
text
()).
toBe
(
'
mixinComputed: 通过字面量定义非全局 mixin computed, 更新后的 mixinOnloadMsg: mixin onLoad msg in onLoad
'
)
})
})
\ No newline at end of file
pages/composition/mixins/mixins-web.uvue
0 → 100644
浏览文件 @
caaca366
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page">
<text id="mixin-prop" class="uni-common-mb">mixinProp: {{mixinProp}}</text>
<text id="mixin-data-msg" class="uni-common-mb">mixinDataMsg: {{mixinDataMsg}}</text>
<text id="mixin-onload-msg" class="uni-common-mb">mixinOnloadMsg: {{mixinOnloadMsg}}</text>
<text id="mixin-computed" class="uni-common-mb">mixinComputed: {{mixinComputed}}</text>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script lang="uts">
export default {
mixins: [defineMixin({
props: {
mixinProp: {
type: String,
default: '通过字面量定义非全局 mixin props'
}
},
data() {
return {
mixinDataMsg: '通过字面量定义非全局 mixin data',
mixinOnloadMsg: ''
}
},
computed: {
mixinComputed() : string {
const res = `通过字面量定义非全局 mixin computed, 更新后的 mixinOnloadMsg: ${this.mixinOnloadMsg}`
console.log(res)
return res
}
},
onLoad() {
this.mixinOnloadMsg = 'mixin onLoad msg in onLoad'
},
methods: {
mixinMethod() : string {
const res = '通过字面量定义非全局 mixin method'
console.log(res)
return res
}
},
})]
}
</script>
\ No newline at end of file
pages/tab-bar/options-api.uvue
浏览文件 @
caaca366
...
@@ -401,16 +401,20 @@
...
@@ -401,16 +401,20 @@
url: 'inject',
url: 'inject',
enable: true,
enable: true,
},
},
// #ifdef APP
{
{
name: 'mixins',
name: 'mixins',
url: 'mixins',
url: 'mixins',
// #ifdef APP
enable: true,
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
},
// #endif
// #ifdef WEB
{
name: 'mixins',
url: 'mixins/mixins-web',
enable: true,
},
// #endif
{
{
name: 'extends',
name: 'extends',
url: 'extends',
url: 'extends',
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录