uniapp 工作常用整理

vue3+vant4新界面模板:帶底部浮動按鈕

<template>
  <div class="page-bg">
    <section class="tl-section-0 mb-10">
      <van-row justify="center">
        <van-col class="tl-font-14-666-400">基本信息</van-col>
        <van-col class="tl-font-14-475-500 ml-91">預(yù)檢信息</van-col>
      </van-row>
      <div class="tl-flex-center" style="height: 21px">
        <div class="tl-point-7"></div>
        <div class="line-w130"></div>
        <img src="@/assets/icon/now.png" class="tl-img-11" alt="" />
      </div>
    </section>

    <div class="height-120"></div>
    <div class="tl-footer tl-flex-bwt">
      <div class="tl-btn-164">返回上一步</div>
      <div class="tl-btn-164-yes">下一步</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.page-bg {
  width: 100vw;
  overflow-y: scroll;
  background-color: #f0f2f4;
}
.tl-section-0 {
  height: 46px;
  background: #ffffff;
  padding: 6px 0;
}
.tl-font-14-475-500 {
  font-size: 14px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #0b457f;
}
.tl-img-11 {
  width: 11px;
  height: 11px;
}
.line-w130 {
  width: 130px;
  height: 1px;
  background: #d8d8d8;
}
.tl-point-7 {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #cccccc;
}
.ml-91 {
  margin-left: 91px;
}
.tl-section {
  height: auto;
  background: #ffffff;
  padding: 12px 15px 18px 12px;
}
.tl-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  height: 54px;
  background: #ffffff;
  padding: 0 15px;
  .tl-btn-164 {
    width: 164px;
    height: 38px;
    line-height: 38px;
    text-align: center;
    background: #ffffff;
    border-radius: 24px 24px 24px 24px;
    border: 1px solid #999999;
    font-size: 16px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
  }

  .tl-btn-164-yes {
    width: 164px;
    height: 38px;
    line-height: 38px;
    text-align: center;
    background: #0b457f;
    border-radius: 24px 24px 24px 24px;
    font-size: 16px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
  }
}

/*重置默認樣式岂丘,間距處理*/
::v-deep .van-cell-group {
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
  margin-right: 0;
}
::v-deep .van-cell {
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
  margin-right: 0;
  line-height: 29px;
  /*border-bottom: 1px solid #e6e6e6;*/
}
::v-deep .van-field__control {
  padding: 0 10px;
}
.tl-border-1 {
  border-bottom: 1px solid #e6e6e6;
}
::v-deep .van-cell:after {
  position: relative;
}
</style>


vue3+vant4新界面模板:

<template>
  <div class="page-bg">
    <section class="tl-section mb-10">
      <div class="tl-font-14-333-500 mb-14">基本信息</div>
      <van-row justify="space-between" class="mb-16">
        <van-col class="tl-font-14-999-400">車主姓名</van-col>
        <van-col class="tl-font-14-333-400">王菲</van-col>
      </van-row>
    </section>
    <div class="height-120"></div>
    <div class="tl-footer tl-flex-bwt">
      <div class="tl-font-16-3d3-400">
        支付金額:<span class="tl-font-20-3d3-500">¥290</span>
      </div>
      <div class="tl-btn-193 active">立即支付</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.page-bg {
  width: 100vw;
  overflow-y: scroll;
  background-color: #f0f2f4;
}
.tl-section {
  height: auto;
  background: #ffffff;
  padding: 12px 15px 18px 12px;
}
.tl-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  height: 54px;
  background: #ffffff;
  padding: 0 15px;

  .tl-btn-193 {
    width: 193px;
    height: 38px;
    line-height: 38px;
    text-align: center;
    background: #f3f3f3;
    border-radius: 24px 24px 24px 24px;
    font-size: 16px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .active {
    background: #0b457f;
    color: #ffffff;
  }
}
</style>


03阻止事件冒泡

@click.stop  阻止事件冒泡

02 存取操作:

uni.setStorageSync('storage_key', 'hello');

uni.getStorageSync('storage_key');

01 新模板:

<template>
  <view class="page-bg">
    <view class="main-container">

    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {

    }
  },
  methods: {

  }
}
</script>

<style lang="less" scoped>
.page-bg {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-size: 750rpx auto;
  background-color: #F9F9F9;
}

.main-container {
  width: 694rpx;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
</style>



再次確認框

let self = this;
   uni.showModal({
   title: '提示信息',
   content: '是否取消關(guān)注當(dāng)前疾簿迪ぁ喘沿?',
   cancelText: "取消",
   confirmText: "確認",
   confirmColor: '#2851F3',
   cancelColor: '#9E9E9E',
   success: function (res) {
   if (res.confirm) {
   self.saveDra(item);
   } else if (res.cancel) {
   console.log('用戶點擊取消');
   }
   }
   });

git回滾到某次提交

git reset --hard xxx
git push origin HEAD --force

git reset --hard HEAD~3 回退到前3次提交之前,以此類推猾骡,回退到n次提交之前
$ git reset --hard commit_id 退到/進到 指定commit的sha碼

強推到遠程:

$ git push origin HEAD --force

作者:CgySHFF
鏈接:http://www.reibang.com/p/5eb2227d5546
來源:簡書
著作權(quán)歸作者所有瑞躺。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處兴想。

02.定時器:

setTimeout(() => {
                this.getList();
              }, 2000)

9.超出顯示省略號:

.tl-word-120 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 120rpx;
}
.tl-word {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 580rpx;
}
.tl-flex{
  display: flex;
}

8.創(chuàng)建新頁面模板:2021-06-15

<template>
    <view class="page-bg">
        <view class="main-container">
        
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                
            }
        },
        methods: {
            
        }
    }
</script>

<style>
    .page-bg {
        width: 100vw;
        height: auto;
        overflow: hidden;
        background-size: 750rpx auto;
        background-color: #fff;
    }

    .main-container {
        width: 710rpx;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
    }
</style>


  1. uniapp 動態(tài)監(jiān)聽按鈕
    http://www.reibang.com/p/2cd8bc592b22

9.ajax封裝


getData() {
        this.$http.post('getMyResidentialInfo', {}).then(([error, res]) => {
          if(res.data.code == 200) {
            let data = res.data.data;
            this.myHome = data.community_info.name;
            //this.cateLists = this.formCate(data.cate)
          } else {
            this.$common.toast(res.data.message)
          }
        })
      },

10.攜帶多參數(shù)界面跳轉(zhuǎn)操作


//跳轉(zhuǎn)界面操作
let params = {
          id: '',
          avatar: '',
          nickname: '',
        }
let tempData = JSON.stringify(params)


uni.navigateTo({
    url: '/pages/publish/preview?tempData=' + encodeURIComponent(tempData),
})



//落腳界面接受處理
onLoad(options){
    let self = this;
    //debugger
    let params = JSON.parse(decodeURIComponent(options.tempData));
    self.showData = params; //界面回顯的數(shù)據(jù)源
    self.showTime = self.timeStamp(params.start_time);

    },

7.異步調(diào)用

let code = await self.getCode(); //獲取一個異步調(diào)用的返回值隘蝎,有了才繼續(xù)執(zhí)行

async getCode() {
                return new Promise((resolve) => {
                    uni.login({
                        provider: 'weixin',
                        success: function(loginRes) {
                            let code = loginRes.code; //重新獲取一次code參數(shù)
                            resolve(code);
                        }
                    });
                });
            },


9.flex 布局 保持橫排不并排操作:


image.png

.box {
flex-direction: row | row-reverse | column | column-reverse;
}

.tl-section{
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
                width:100%;
    }


<view class="tl-section">
                <view class="tl-font-28-686">當(dāng)前糖果</view>
                <view class="tl-font-48-900">157.54</view>
                <view>
                    <button class="tl-btn tl-font-28-red">兌換</button>
                </view>
            </view>

image.png

8 驗證碼 倒計時


// 驗證碼
            navCheck() {
                if (this.codetime > 0) return; //校驗短信倒計時
                if (!(/^1[3456789]\d{9}$/.test(this.mobile))) {
                    uni.showToast({
                        icon: 'none',
                        mask: true,
                        title: '手機號有誤'
                    });
                    return;
                }

                let params = {
                    mobile: this.mobile
                };
                //todo 待對接驗證碼接口
                this.$http.post('sendCode', params,{token: 'token'}).then(([error, res])=>{
                    if(res.data.code == 1) {
                        uni.showToast({
                            title:'驗證碼發(fā)送成功',
                            icon:'none',
                        })
                        //驗證碼倒計時
                        this.codetime = 120;
                        let timer = setInterval(() => {
                            this.codetime--;
                            if (this.codetime < 1) {
                                clearInterval(timer);
                                this.codetime = 0;
                            }
                        }, 1000);
                    }else {
                        uni.showModal({
                            title: '提示',
                            showCancel: false,
                            content: res.data.msg,
                            success: function (res) {
                                if (res.confirm) {
                                    console.log('用戶點擊確定');
                                } else if (res.cancel) {
                                    console.log('用戶點擊取消');
                                }
                            }
                        });
                        /*uni.showToast({
                            icon: 'none',
                            mask: true,
                            title: res.data.msg,
                            duration: 2500
                        });*/
                    }

                })
            },

    if(res.data.code == 1){

}else if(res.data.code != 1){
    uni.showToast({
    title: res.data.msg,
    icon:'none',
    duration: 2000
  })
}


{
    name: '張三三',
    time: '2020-2-5 12:50',
    profit: '2.5'
}

6.css3 勾勾特效

image.png
.feature i {
    width: 14px;
    height: 6px;
    display: inline-block;
    border: 1px solid #23b8ff;
    border-width: 0 0 2px 2px;
    transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    -moz-transform: rotate(-45deg);
    -webkit-transform: rotate(-45deg); 
    -o-transform: rotate(-45deg);
    vertical-align: baseline;
}

5.掃碼進入或者用戶點擊分享進入(2020-12-12):

if(options && options.serviceId){ //用戶點擊分享連接進入
                self.serviceId = options.serviceId;
            }else if(options && options.q){
                let url = decodeURIComponent(options.q);
                let serviceId = (url.match(/serviceId=(\w+)/) ? url.match(/serviceId=(\w+)/)[1] : null);
                console.log("serviceId===================serviceId==",serviceId);
                this.serviceId = serviceId;
            }

4.消息提示框:

uni.showToast({
                            title: res.data.msg,
                            icon:'none',
                            duration: 2000//延遲顯示
                        })

1.線上ajax操作

//查詢當(dāng)前訂單是否送券
            getCoupons(orderId){
                request({
                    url: inter.getConsumerCouponStatus,
                    data: {
                        orderId: orderId
                    },
                    callback: (res) => {
                        if(res.CODE==-1){
                            uni.showToast({
                                title: res.MESSAGE,
                                icon: false
                            });
                            return false;
                        }

                        if(!res.RESULT.hasConsumerCoupon){ // true 用戶獲取了優(yōu)惠券
                            uni.showToast({
                                title: '本次消費已獲贈消費券',
                                icon: 'none',
                                mask: true,
                                duration: 1500
                            });
                        }

                        setTimeout(() => {
                            uni.reLaunch({
                                url: '/pages/home/home'
                            })
                        }, 2000)
                    }
                })

            }

  1. 暫時去掉的菜單欄:
{
            "pagePath": "pages/exam/exam",
            "iconPath": "static/index_84.png",
            "selectedIconPath": "static/order_06.png",
            "text": "考試"
        }

3.定時函數(shù):

setTimeout(() => {
                                        
                                    }, 300)

66.map

let list = data.data.map(item => {
                            item.goods_advertise_price = parseFloat(item.goods_advertise_price)
                            item.goods_price = parseFloat(item.goods_price)
                            return item
                        })
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市襟企,隨后出現(xiàn)的幾起案子嘱么,更是在濱河造成了極大的恐慌,老刑警劉巖顽悼,帶你破解...
    沈念sama閱讀 216,591評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件曼振,死亡現(xiàn)場離奇詭異,居然都是意外死亡蔚龙,警方通過查閱死者的電腦和手機冰评,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,448評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來木羹,“玉大人甲雅,你說我怎么就攤上這事】犹睿” “怎么了抛人?”我有些...
    開封第一講書人閱讀 162,823評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長脐瑰。 經(jīng)常有香客問我妖枚,道長,這世上最難降的妖魔是什么苍在? 我笑而不...
    開封第一講書人閱讀 58,204評論 1 292
  • 正文 為了忘掉前任绝页,我火速辦了婚禮荠商,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘续誉。我一直安慰自己莱没,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,228評論 6 388
  • 文/花漫 我一把揭開白布酷鸦。 她就那樣靜靜地躺著郊愧,像睡著了一般。 火紅的嫁衣襯著肌膚如雪井佑。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,190評論 1 299
  • 那天眠寿,我揣著相機與錄音躬翁,去河邊找鬼。 笑死盯拱,一個胖子當(dāng)著我的面吹牛盒发,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播狡逢,決...
    沈念sama閱讀 40,078評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼宁舰,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了奢浑?” 一聲冷哼從身側(cè)響起蛮艰,我...
    開封第一講書人閱讀 38,923評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎雀彼,沒想到半個月后壤蚜,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,334評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡徊哑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,550評論 2 333
  • 正文 我和宋清朗相戀三年袜刷,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片莺丑。...
    茶點故事閱讀 39,727評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡著蟹,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出梢莽,到底是詐尸還是另有隱情萧豆,我是刑警寧澤,帶...
    沈念sama閱讀 35,428評論 5 343
  • 正文 年R本政府宣布昏名,位于F島的核電站炕横,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏葡粒。R本人自食惡果不足惜份殿,卻給世界環(huán)境...
    茶點故事閱讀 41,022評論 3 326
  • 文/蒙蒙 一膜钓、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧卿嘲,春花似錦颂斜、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,672評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至梅肤,卻和暖如春司蔬,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背姨蝴。 一陣腳步聲響...
    開封第一講書人閱讀 32,826評論 1 269
  • 我被黑心中介騙來泰國打工俊啼, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人左医。 一個月前我還...
    沈念sama閱讀 47,734評論 2 368
  • 正文 我出身青樓授帕,卻偏偏與公主長得像,于是被迫代替她去往敵國和親浮梢。 傳聞我的和親對象是個殘疾皇子跛十,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,619評論 2 354

推薦閱讀更多精彩內(nèi)容