提交 feb27aed 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: setNavigationBarTitle 补充超长标题示例

上级 6fde3b0e
...@@ -16,11 +16,16 @@ describe("setNavigationBarColor", () => { ...@@ -16,11 +16,16 @@ describe("setNavigationBarColor", () => {
expect(lifeCycleNum).toBe(originLifeCycleNum); expect(lifeCycleNum).toBe(originLifeCycleNum);
}); });
it("setNavigationBarTitle", async () => { it("setNavigationBarNewTitle", async () => {
await page.callMethod("setNavigationBarTitle"); await page.callMethod("setNavigationBarNewTitle");
const image = await program.screenshot(); const image = await program.screenshot();
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
const lifeCycleNum = await page.callMethod("getLifeCycleNum"); const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(2); expect(lifeCycleNum - originLifeCycleNum).toBe(2);
}); });
it("setNavigationBarLongTitle", async () => {
await page.callMethod("setNavigationBarLongTitle");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
});
}); });
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
<view> <view>
<page-head title="setNavigationBarTitle"></page-head> <page-head title="setNavigationBarTitle"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<button @tap="setNavigationBarTitle" class="uni-btn"> <button @tap="setNavigationBarNewTitle" class="uni-btn">
设置当前页面的标题为 {{ newTitle }} 设置当前页面标题为: {{ newTitle }}
</button>
<button @tap="setNavigationBarLongTitle" class="uni-btn">
设置超长标题
</button> </button>
</view> </view>
</view> </view>
...@@ -15,11 +18,12 @@ import { state, setLifeCycleNum } from '@/store/index.uts' ...@@ -15,11 +18,12 @@ import { state, setLifeCycleNum } from '@/store/index.uts'
export default { export default {
data(){ data(){
return { return {
newTitle: 'new title' newTitle: 'new title',
longTitle: 'long title long title long title long title long title long title long title long title long title long title'
} }
}, },
methods: { methods: {
setNavigationBarTitle() { setNavigationBarNewTitle() {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: this.newTitle, title: this.newTitle,
success() { success() {
...@@ -27,7 +31,7 @@ export default { ...@@ -27,7 +31,7 @@ export default {
this.setLifeCycleNum(state.lifeCycleNum + 1) this.setLifeCycleNum(state.lifeCycleNum + 1)
}, },
fail() { fail() {
console.log('setNavigationBarTitle success') console.log('setNavigationBarTitle fail')
this.setLifeCycleNum(state.lifeCycleNum - 1) this.setLifeCycleNum(state.lifeCycleNum - 1)
}, },
complete() { complete() {
...@@ -36,6 +40,20 @@ export default { ...@@ -36,6 +40,20 @@ export default {
} }
}) })
}, },
setNavigationBarLongTitle() {
uni.setNavigationBarTitle({
title: this.longTitle,
success() {
console.log('setNavigationBarTitle success')
},
fail() {
console.log('setNavigationBarTitle fail')
},
complete() {
console.log('setNavigationBarTitle complete')
}
})
},
// 自动化测试 // 自动化测试
getLifeCycleNum(): number { getLifeCycleNum(): number {
return state.lifeCycleNum return state.lifeCycleNum
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册