工具:微信開發(fā)者工具
1.如何獲取data中的值? 使用this.data.
2.如何修改data中的值?使用 this.setData({key: value}),其中key為data中修改的數(shù)據(jù),value為要修改的值
3.如何存儲數(shù)據(jù)? 1.簡單數(shù)據(jù)wx.setStorage({ key: ‘key’,data: value} 2.對象類數(shù)據(jù)wx.setStorage({ key: ‘key’,data: {}}
4.跳轉(zhuǎn)外部鏈接?
<web-view src=""></web-view>
5.拿到存儲的值,并修改data的值 wx.getStorageSync(‘key’)
let name1 = wx.getStorageSync('name1');
console.log(name1);
- 動態(tài)獲取設(shè)備寬高wx.getSystemInfo({ })
- 修改頭部標題
// xxx.js 第一種
onLoad () {
wx.setNavigationBarTitle({
title: '進入群認證',
})
}
// xxx.json 第二種
{
"navigationBarTitleText": "", // 此處修改
"usingComponents": {}
}
例子:
/*
xxx.wxml 存放標簽
xxx.wxss 存放css
xxx.js 存放js,邏輯
*/
// xxx.wxml
<view class="container">
{{ userInfo }}
<br/>
{{ userInfo.name }}
<br/>
{{ userInfo.age }}
<!--方法start-->
<button bindtap="onSet">存儲數(shù)據(jù)</button>
<view style="width: {{width}}px;height:{{height}}px"></view>
</view>
// xxx.js
Page({
data: {
width: 0,
height: 0,
userInfo: {
name: 'cc',
age: 18
},
// 獲取存儲的值
name1: wx.getStorageSync('name1') || '',
userInfo1: wx.getStorageSync('userInfo1') || {}
},
onLoad () { // 加載 類似created,mounted
wx.setNavigationBarTitle({ //修改頭部標題
title: '進入群認證',
})
wx.getSystemInfo({ // 動態(tài)獲取設(shè)備寬高
success: res => {
const { windowWidth, windowHeight } = res;
this.setData({
width: windowWidth,
height: windowHeight
})
}
})
let userInfo = this.data.userInfo;
console.log(userInfo);
console.log(userInfo.name);
console.log(userInfo.age);
// 修改data里面的值
this.setData({
userInfo: {
name: 'mm',
age: 20
}
})
},
// 方法
onSet () { // 存儲 數(shù)據(jù)
wx.setStorage({
key: 'name1',
data: 'cc'
})
wx.setStorage({
key: 'userInfo',
data: this.data.userInfo || {}
})
},
onGet () { // 獲取數(shù)據(jù)
let name1 = wx.getStorageSync('name1');
console.log(name1);
this.setData({
name1: name1
})
wx.getStorage({
key: 'userInfo1',
success(res) {
console.log('1111', res.data)
}
})
},
onPage () { // 跳轉(zhuǎn)頁面
location.;
}
})
結(jié)果:
5.如何查看存儲的數(shù)據(jù)?點擊調(diào)試器–>Stroage文章來源:http://www.zghlxwxcb.cn/news/detail-495149.html
注意點:
1.使用的時候會立刻馬上跳轉(zhuǎn)到頁面,如果使用點擊事件,要重新建立一個新頁面,然后把放在.wxml中
2. 不能使用location.href跳轉(zhuǎn)頁面
3. 當連接后端的時候,1.關(guān)閉防火墻,2.下面這張圖片
否則報錯文章來源地址http://www.zghlxwxcb.cn/news/detail-495149.html
到了這里,關(guān)于如何獲取data中的值?如何取出,存儲數(shù)據(jù)?跳轉(zhuǎn)外部鏈接?與非本機聯(lián)調(diào)?修改頭部標題?動態(tài)更改樣式?動態(tài)獲取設(shè)備寬高?(微信小程序)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!