二丶 js
开发者:MJcc1111 a763137841 dilidili lin_xi fuqiou lql213 test123456
域名配置
request 合法域名
https://www.adota.cn
https://static.adota.cn
socket 合法域名
uploadFile 合法域名
https://www.adota.cn
https://up-z2.qiniup.com
downloadFile 合法域名
https://www.adota.cn
https://static.adota.cn
看广告,绑定,分享,上报
HTML:
<dio-share></dio-share>
<view v-show="douamry" style="position: absolute;font-size: 24rpx;top: 110rpx;left: 20rpx;align-self: flex-start;z-index: 999;">id:{{ douamry }}</view>
import {config} from "@/common/lib/app.js"
import { mapState, mapMutations } from 'vuex';
import { loggerShare, shareParam } from '../../common/tt.mini.js';
computed: {
...mapState(['userInfo'])
...mapState(['threadId','goodsMode','douamry']),
}
...mapMutations(['setState']) //放 methods 里
onShareAppMessage: function(shareOption) {
let shareparam = shareParam(shareOption);
loggerShare();
return shareparam;
}
video.ViodeAd.goodsId ='5f99221fff18333f42bd1f78';
new video.ViodeAd(self.reward,'11i5eb9h1gqc45c2i8')
放 onLoad 里
if(e.share){
if(config.userInfo.id){
this.$reports.report('/pages/kitchen_testIndex/kitchen_testIndex',JSON.stringify(e),false)
}
else{
uni.$once('login-temp-ok', function(){
self.$reports.report('/pages/kitchen_testIndex/kitchen_testIndex',JSON.stringify(e),false)
});
}
}else{
this.$reports.report('/pages/kitchen_testIndex/kitchen_testIndex',JSON.stringify(e),true)
}
// 获取产品字典数据
this.$dio.dio('dicts/string', {
key: '_id',
value: config.dictKey //字典值
}).then(data => {
let value = data?.data?.data.value || {};
this.setState({ goodsMode: value }); // 产品字典里的数据
config.dynamicShareParam = value.dynamicShareParam; //分享文案
})
1.小程序默认去掉头部标题,在 path 字段下加如下代码
"style": {
"navigationStyle": "custom",
"enablePullDownRefresh":true, //下拉刷新
"onReachBottomDistance":50 //下拉刷新
}
onPullDownRefresh() {
console.log("正在下拉")
uni.stopPullDownRefresh(); //下拉之后停止下来
}
tabBar 例子
"tabBar": {
"color": "#080808",
"selectedColor": "#080808",
"borderStyle": "#4368c9",
"backgroundColor": "#4368c9",
"list": [{
"pagePath": "pages/answerIndex/answerIndex",
"iconPath": "/static/answerIndex/tabBar_home.png",
"selectedIconPath": "/static/answerIndex/tabBar_homeA.png"
,
"text": "首页"
},{
"pagePath": "pages/answerData/answerData",
"iconPath": "/static/answerIndex/tabBar_data.png",
"selectedIconPath": "/static/answerIndex/tabBar_dataA.png"
,
"text": "数据"
}, {
"pagePath": "pages/answerMy/answerMy",
"iconPath": "/static/answerIndex/tabBar_my.png",
"selectedIconPath": "/static/answerIndex/tabBar_myA.png"
,
"text": "我的"
}]
}
2.返回上一页
redirectTo
uni.navigateBack({
delta: 1
});
uni.navigateTo({
url: '../chicken_choosing/chicken_choosing'
});
3.提示弹窗
uni.showToast({
title: '请写下您的心情内容~',
duration: 2000,
icon:'none'
});
4.设置粘贴板内容
uni.setClipboardData({
data:
``
success: function () {
console.log('success');
}
});
4.页面传参数为数组,
将参数转为 JSON 字符串 JSON.stringify(对象)
接收页面转为数组对象 JSON.parse(字符串)
5.得出今日日期
(1).
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : "0" + parseInt(date.getMonth() + 1);
let day = date.getDate();
this.date = year + "." + month + "." + day;
(2)js 获取当前日期方法(YYYY-MM-DD 格式)
var time = myDate.toLocaleDateString().split('/').join('-');将 1970/08/08 转化成 1970-08-08(iOS 不兼容)
获取天数:(new Date("2021-01-22").getTime()-new Date("2021-01-20").getTime())/ 1000 / 60 / 60 /24(iOS 兼容)
6.比较两个日期之间相距多少天
DateDiff(sDate1, sDate2){ //sDate1 和 sDate2 是 2002-12-18 格式
let iDays;
let sDate1=new Date(sDate1);
let sDate2=new Date(sDate2);
let iDays = parseInt(Math.abs(sDate1 - sDate2) / 1000 / 60 / 60 /24); //把相差的毫秒数转换为天数
return iDays;
}
6.登录
tryLogin(){
if(this.userInfo?.nickName){
return;
}
// 获取用户信息
uni.getUserInfo({
success(e) {
self.setState({userInfo:{...e.userInfo,...self.userInfo}})
uni.setStorageSync('userInfo',self.userInfo)
},
fail(error) {
console.log(error);
uni.openSetting({
success(res) {
uni.getUserInfo({
success(e) {
console.log(e);
self.setState({userInfo:{...e.userInfo,...self.userInfo}})
uni.setStorageSync('userInfo',self.userInfo)
}
})
}
});
}
})
}
7.清除缓存,苹果手机失效
if(e.query.clearstorage){
// uni.clearStorage();
uni.clearStorageSync()
uni.showToast({
title:'清除本地缓存成功'
})}
8.用 js 取 1-100 的随机数 https://www.cnblogs.com/xyn0909/p/8574926.html
function sum (m,n){
var num = Math.floor(Math.random()*(m - n) + n);
alert(num)
}
sum(1,100);
8.获取节点元素高度
let query = uni.createSelectorQuery();
query.select('#id').boundingClientRect();
query.exec(function (res) {
console.log("当前元素的 res:",res) console.log(res[0].width, res[0].height,res[0].top);
});
9.获取数字数组前 n 个数字相加的和?
getListValue(list, max) {
var total = 0;
for (let i = 0; i < max; i++) {
total = total + list[i];
}
return total;
}
10.获取数组中 n 个不重复元素组成的新数组?
getRandomArrayElements(arr, count) {
var shuffled = arr.slice(0),
i = arr.length,
min = i - count,
temp, index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于