Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
af3d7ca0
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
401
Star
3
Fork
10
代码
文件
提交
分支
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看板
提交
af3d7ca0
编写于
11月 23, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(web): 优化 web 端不兼容 api 及 代码示例
上级
85e1196f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
260 addition
and
237 deletion
+260
-237
App.uvue
App.uvue
+154
-153
pages/component-instance/attrs/child.uvue
pages/component-instance/attrs/child.uvue
+18
-2
pages/component-instance/parent/child.uvue
pages/component-instance/parent/child.uvue
+4
-0
pages/component-instance/refs/refs.uvue
pages/component-instance/refs/refs.uvue
+2
-2
pages/component-instance/slots/slot.uvue
pages/component-instance/slots/slot.uvue
+3
-3
pages/lifecycle/component/component.test.js
pages/lifecycle/component/component.test.js
+1
-0
pages/lifecycle/page/page.test.js
pages/lifecycle/page/page.test.js
+73
-72
pages/state/data/data.uvue
pages/state/data/data.uvue
+3
-3
pages/state/methods/methods.uvue
pages/state/methods/methods.uvue
+2
-2
未找到文件。
App.uvue
浏览文件 @
af3d7ca0
<script lang="uts">
import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './store/index.uts'
let firstBackTime = 0
export default {
onLaunch: function (options) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
setAppLaunchPath(options.path)
console.log('App Launch')
const performance = uni.getPerformance()
const observer: PerformanceObserver = performance.createObserver((entryList: PerformanceObserverEntryList) => {
console.log('observer:entryList.getEntries()')
console.log(entryList.getEntries())
})
observer.observe({
entryTypes: ['render', 'navigation'],
} as PerformanceObserverOptions)
},
onShow: function (options) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100)
setAppShowPath(options.path)
console.log('App Show')
},
onHide: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 100)
console.log('App Hide')
},
onLastPageBackPress: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1000)
console.log('App LastPageBackPress')
if (firstBackTime == 0) {
uni.showToast({
title: '再按一次退出应用',
position: 'bottom',
})
firstBackTime = Date.now()
setTimeout(() => {
firstBackTime = 0
}, 2000)
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = Date.now()
uni.exit()
}
},
onExit() {
console.log('App Exit')
},
methods: {
checkLaunchPath(): boolean{
const HOME_PATH = '/pages/index'
if(state.appLaunchPath != HOME_PATH){
return false
}
if(state.appShowPath != HOME_PATH){
return false
}
return true
}
}
}
</script>
<style>
/* @font-face {
font-family: uniicons;
font-weight: normal;
font-style: normal;
src: url('./static/fonts/uni.ttf') format('truetype');
} */
.page {
padding: 15px;
}
.uni-panel {
margin-bottom: 12px;
}
.uni-panel-h {
background-color: #ffffff;
flex-direction: row;
align-items: center;
padding: 12px;
}
.uni-panel-h-on {
background-color: #f0f0f0;
}
.uni-panel-text {
color: #000000;
font-size: 14px;
font-weight: normal;
}
.uni-panel-icon-on {
transform: rotate(180deg);
}
.uni-navigate-item {
flex-direction: row;
align-items: center;
background-color: #ffffff;
border-top-style: solid;
border-top-color: #f0f0f0;
border-top-width: 1px;
padding: 12px;
justify-content: space-between;
}
.uni-navigate-item:active {
background-color: #f8f8f8;
}
.uni-navigate-text {
color: #000000;
font-size: 12px;
opacity: 0.8;
}
.uni-navigate-icon {
margin-left: 15px;
color: #999999;
font-size: 14px;
font-weight: normal;
}
.text-disabled {
color: #a0a0a0;
}
.list-item-text {
line-height: 36px;
}
.split-title {
margin: 20px 0 5px;
padding: 5px 0;
border-bottom: 1px solid #dfdfdf;
}
.btn-view {
margin: 10px 0;
padding: 10px;
border: 1px solid #dfdfdf;
border-radius: 3px;
}
</style>
<script lang="uts">
import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './store/index.uts'
let firstBackTime = 0
export default {
onLaunch: function (options) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
setAppLaunchPath(options.path)
console.log('App Launch')
// #ifdef UNI-APP-X && APP-ANDROID
const performance = uni.getPerformance()
const observer : PerformanceObserver = performance.createObserver((entryList : PerformanceObserverEntryList) => {
console.log('observer:entryList.getEntries()')
console.log(entryList.getEntries())
})
observer.observe({
entryTypes: ['render', 'navigation'],
} as PerformanceObserverOptions)
// #endif
},
onShow: function (options) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100)
setAppShowPath(options.path)
console.log('App Show')
},
onHide: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 100)
console.log('App Hide')
},
onLastPageBackPress: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1000)
console.log('App LastPageBackPress')
if (firstBackTime == 0) {
uni.showToast({
title: '再按一次退出应用',
position: 'bottom',
})
firstBackTime = Date.now()
setTimeout(() => {
firstBackTime = 0
}, 2000)
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = Date.now()
uni.exit()
}
},
onExit() {
console.log('App Exit')
},
methods: {
checkLaunchPath() : boolean {
const HOME_PATH = '/pages/index'
if (state.appLaunchPath != HOME_PATH) {
return false
}
if (state.appShowPath != HOME_PATH) {
return false
}
return true
}
}
}
</script>
<style>
/* @font-face {
font-family: uniicons;
font-weight: normal;
font-style: normal;
src: url('./static/fonts/uni.ttf') format('truetype');
} */
.page {
padding: 15px;
}
.uni-panel {
margin-bottom: 12px;
}
.uni-panel-h {
background-color: #ffffff;
flex-direction: row;
align-items: center;
padding: 12px;
}
.uni-panel-h-on {
background-color: #f0f0f0;
}
.uni-panel-text {
color: #000000;
font-size: 14px;
font-weight: normal;
}
.uni-panel-icon-on {
transform: rotate(180deg);
}
.uni-navigate-item {
flex-direction: row;
align-items: center;
background-color: #ffffff;
border-top-style: solid;
border-top-color: #f0f0f0;
border-top-width: 1px;
padding: 12px;
justify-content: space-between;
}
.uni-navigate-item:active {
background-color: #f8f8f8;
}
.uni-navigate-text {
color: #000000;
font-size: 12px;
opacity: 0.8;
}
.uni-navigate-icon {
margin-left: 15px;
color: #999999;
font-size: 14px;
font-weight: normal;
}
.text-disabled {
color: #a0a0a0;
}
.list-item-text {
line-height: 36px;
}
.split-title {
margin: 20px 0 5px;
padding: 5px 0;
border-bottom: 1px solid #dfdfdf;
}
.btn-view {
margin: 10px 0;
padding: 10px;
border: 1px solid #dfdfdf;
border-radius: 3px;
}
</style>
\ No newline at end of file
pages/component-instance/attrs/child.uvue
浏览文件 @
af3d7ca0
...
...
@@ -15,7 +15,7 @@
</view>
</template>
<script>
<script
lang='uts'
>
export default {
emits: ['result'],
props: {
...
...
@@ -25,14 +25,30 @@ export default {
}
},
computed: {
hasPropsAttrs (): boolean {
hasPropsAttrs(): boolean {
// #ifdef UNI-APP-X && APP-ANDROID
return this.$attrs.has('val')
// #endif
// #ifdef UNI-APP-X && WEB
return !!this.$attrs['val']
// #endif
},
hasEmitsAttr (): boolean {
// #ifdef UNI-APP-X && APP-ANDROID
return this.$attrs.has('result')
// #endif
// #ifdef UNI-APP-X && WEB
return !!this.$attrs['result']
// #endif
},
hasAttrs (): boolean {
// #ifdef UNI-APP-X && APP-ANDROID
return this.$attrs.has('class')
// #endif
// #ifdef UNI-APP-X && WEB
return !!this.$attrs['class']
// #endif
}
}
}
...
...
pages/component-instance/parent/child.uvue
浏览文件 @
af3d7ca0
...
...
@@ -19,7 +19,11 @@ export default {
},
methods: {
testFunction () {
// #ifdef UNI-APP-X && APP-ANDROID
this.callbackValue = this.$parent!.$callMethod('testFunction') as string
// #endif
// TODO: 非 app-android 简单绕过, web 无法通过 this.$parent.functionName 调用父组件 methods 中的方法
this.callbackValue = 'parentFunctionResult'
}
}
}
...
...
pages/component-instance/refs/refs.uvue
浏览文件 @
af3d7ca0
...
...
@@ -5,7 +5,7 @@
</view>
</template>
<script>
<script
lang='uts'
>
// import child from './child.uvue'
export default {
...
...
@@ -18,7 +18,7 @@ export default {
}
},
mounted () {
const nodeRef = this.$refs
.get('node')
const nodeRef = this.$refs
['node']
this.existRef = nodeRef !== null
...
...
pages/component-instance/slots/slot.uvue
浏览文件 @
af3d7ca0
...
...
@@ -5,15 +5,15 @@
</view>
</template>
<script>
<script
lang='uts'
>
export default {
mounted () {
console.log(this.hasSlots())
},
methods: {
hasSlots (): boolean {
const header = this.$slots
.get('header')
const footer = this.$slots
.get('footer')
const header = this.$slots
['header']
const footer = this.$slots
['footer']
return header !== null && footer !== null
}
...
...
pages/lifecycle/component/component.test.js
浏览文件 @
af3d7ca0
...
...
@@ -28,6 +28,7 @@ describe('component-lifecycle', () => {
})
it
(
'
beforeUpdate updated
'
,
async
()
=>
{
const
component
=
await
page
.
$
(
'
.component-lifecycle
'
)
console
.
log
(
'
component
'
,
component
)
await
component
.
setData
({
title
:
'
component for lifecycle test new title
'
})
...
...
pages/lifecycle/page/page.test.js
浏览文件 @
af3d7ca0
...
...
@@ -4,80 +4,81 @@ let page
let
lifeCycleNum
describe
(
'
app-lifecycle
'
,
()
=>
{
it
(
'
onLaunch onShow
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1100
)
})
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
0
)
})
it
(
'
onLaunch onShow
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1100
)
})
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
100
)
}
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
0
)
})
})
describe
(
'
page-lifecycle
'
,
()
=>
{
afterAll
(
async
()
=>
{
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
afterAll
(
async
()
=>
{
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
it
(
'
onLoad onShow onReady
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
waitFor
(
1500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
await
program
.
pageScrollTo
(
2000
)
const
data
=
await
page
.
data
()
expect
(
data
.
isScrolled
).
toBe
(
true
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
HOME_PATH
)
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
10
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
0
)
})
it
(
'
onUnload
'
,
async
()
=>
{
page
=
await
program
.
redirectTo
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onLoad onShow onReady
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
waitFor
(
1500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
await
program
.
pageScrollTo
(
2000
)
const
data
=
await
page
.
data
()
expect
(
data
.
isScrolled
).
toBe
(
true
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
HOME_PATH
)
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
10
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
0
)
})
it
(
'
onUnload
'
,
async
()
=>
{
page
=
await
program
.
redirectTo
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
it
(
'
onBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
700
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
'
view
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
10
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
})
})
\ No newline at end of file
pages/state/data/data.uvue
浏览文件 @
af3d7ca0
...
...
@@ -35,7 +35,7 @@
</view>
</template>
<script>
<script
lang='uts'
>
type myObj = { name : string, age : number };
// 理论上支持但不支持的写法
...
...
@@ -53,7 +53,7 @@
onLoad() {
console.log('获取所有 data 中的变量',this.$data);
console.log('获取data中的变量num',this.num);
console.log('获取data中的变量num',this.$data
.get('num')
);
console.log('获取data中的变量num',this.$data
['num']
);
}
}
</script>
...
...
@@ -73,4 +73,4 @@
.column{
flex-direction: column;
}
</style>
\ No newline at end of file
</style>
pages/state/methods/methods.uvue
浏览文件 @
af3d7ca0
...
...
@@ -12,7 +12,7 @@
</view>
</template>
<script>
<script
lang='uts'
>
export default {
data() {
return {
...
...
@@ -25,7 +25,7 @@
this.num ++
},
getMultiply100Num() : number{
return num * 100
return
this.
num * 100
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录