pages.json里的设置
1、style下的navigationBarTextStyle属性指的是顶部导航栏的返回键颜色,black(黑色)/white(白色)
uniapp的图片预览,例如arr=[图片1,图片2,…]
uni.previewImage({
current:url, //图片的当前链接 例:图片1
urls:list //该图片所在的图片列表,为数组 例:arr
})
uniapp在main.js里封装一个方法,然后在其他页面使用,并且获得这个方法的返回值
//main.js
export default{
data(){
return{
token:''
}
}
}
Vue.prototype.getSor=function(){
//获取到token值
let that=this
uni.getStorage({ //在里面return结果为空,需要在外面return
key: 'token_key',
success: function(res) {
if(res.data==''){
that.token = ''
}else{
that.token = res.data
}
}
});
return that.token
}
//在需要使用到getSor()这个函数的页面
console.log(this.getSor()); //就能获得到返回的值
在html的style中使用动态数值(class也差不多一样的用法)
<!-- 模板字符串型,注意:样式要使用驼峰 -->
<view :style="{backgroundImage:`url(${barrageData.bg})`,top:`${statusBarHeight}px`}"></view>
<!-- 拼接型 -->
<view :style="{paddingTop:statusBarHeight + 'px',height:'calc(88rpx + 44px + ' + statusBarHeight + 'px)'}"></view>
<!-- 三目运算型 -->
<view :style="index == 2 ?'height:608rpx':''"></view>
<view :style="{ height: index != 0 ? swiperHeight + 'rpx' : 'calc(100vh - 502rpx)' }"></view>
<!-- 赋值型 -->
<view :style="styleObj"></view>
export default{
props:{
styleObj:{
type: Object,
default: function () {
return {}
}
}
}
}
<!-- 赋值型,经过计算 -->
<view :style="[maskStyle, zoomStyle]"></view>
computed:{
maskStyle(){
let style = {};
style.backgroundColor = "rgba(0, 0, 0, 0.6)";
...
return style;
},
zoomStyle(){
...
}
}
克隆数组
const arr = [1,2,3,4,5]
const clone = [].concat(arr)
let clone = JSON.parse(JSON.stringify(arr))