微信小程序轉(zhuǎn)uni-app之基礎(chǔ)語(yǔ)法(組件)

參考:從其他項(xiàng)目轉(zhuǎn)uniapp

1. 視圖容器

1.1 view

(1)eg1

<view class="artList">
    <block v-for="(item,index) in artList" :key="index">
        <view class="item" v-if="item.type == 'image'">
            <image :src="item.content" :data-index="index" mode="widthFix" @tap="removeImg"/>
        </view>
        <view class="item" v-if="item.type=='text'">
            <textarea :value="item.content" placeholder="" v-model="artList[index].content"></textarea>
            <view :data-index="index" class="deleteText" @tap="deleteText">刪除</view>
        </view>
    </block>
</view>

(2)eg2

<!-- 提交按鈕 -->
<view class="submitNow" v-if="artList.length > 0" @tap="submitNow">編輯文章</view>

(3)eg3

<view style="height:50upx;"></view>

(4)eg4

<!-- 文章內(nèi)容區(qū) -->
        <view class="grace-news-list">
            <block v-for="(item,index) in artList" :key="index">
                <!-- 一張圖 -->
                <navigator v-if="item.art_content.length < 3" open-type="navigate" :url="'../info/info?artid=' + item.art_id">
                    <view class="grace-news-list-img-news">
                        <view class="grace-news-list-title-main">{{item.art_title}}</view>
                        <view class="grace-news-list-img-big">
                            <image :src="item.art_content[0]" mode="widthFix"></image>
                        </view>
                    </view>
                </navigator>
                <!-- 三張圖 -->
                <navigator v-if="item.art_content.length >= 3" :url="'../info/info?artid=' + item.art_id">
                    <view class="grace-news-list-img-news">
                        <view class="grace-news-list-title-main">{{item.art_title}}</view>
                        <view class="grace-news-list-imgs">
                            <view class="imgs"><image :src="item.art_content[0]" mode="widthFix"></image></view>
                            <view class="imgs"><image :src="item.art_content[1]" mode="widthFix"></image></view>
                            <view class="imgs"><image :src="item.art_content[2]" mode="widthFix"></image></view>
                        </view>
                    </view>
                </navigator>
            </block>
        </view>

(5)eg5

<view class='item' v-for="(item,index) in orderList" :key="key" v-for-item="item" v-for-index="index" @tap='bindViewDetail' data-machine-sn="item.sn">
    <icon class='iconfont uc-liebiao'></icon>
    <view class='item-name'>
        <view class='machine-name'>{{item.name}}</view>
        <view class='machine-sn'>{{item.sn}}</view>
    </view>
    <view class='item-num'>{{item.number}}</view>
</view>

改為:

<view class='item' v-for="(item,index) in orderList" :key="key" @tap='bindViewDetail' :data-machine-sn="item.sn">
    <icon class='iconfont uc-liebiao'></icon>
    <view class='item-name'>
        <view class='machine-name'>{{item.name}}</view>
        <view class='machine-sn'>{{item.sn}}</view>
    </view>
        <view class='item-num'>{{item.number}}</view>
</view>

(6)eg6

<view class="btn-view">
  <view class="btn-view-con" wx:for="{{btn_arr}}" wx:key="{{index}}" wx:if="{{userInfo.is_root=='1'?true:index=='1'?false:true}}">
    <view class="circle_view_con">
      <view class="circle_view" style="width:{{windowWidth*0.5/3}}px;height:{{windowWidth*0.5/3}}px;border-radius:50%;margin:{{windowWidth*0.25/3-2}}px;margin-bottom:{{windowWidth*0.1/3}}px;"  bindtap="{{item.bindthing}}" >
        <image src="{{item.img_src}}"></image>
      </view>
    </view>
    <text>{{item.text}}</text>
  </view>
</view>

this.setData({
      btn_arr: [{
        bindthing: "switchTo",
        img_src: "/images/my/fengrenji.png",
        text: this.data.T_D.machine
      }, {
        bindthing: "navigatorToStaffPage",
        img_src: "/images/my/users.png",
        text: this.data.T_D.staff
      }, {
        bindthing: "",
        img_src: "/images/my/jk_service.png",
        text: this.data.T_D.service
      }]
    });

switchTo:function(){
    wx.switchTab({
      url: '../machine/index' 
    }) 
  },
  navigatorToStaffPage: function () {
    wx.navigateTo({
      url: "../employee/index"
    })
  },

改為:

<template>
    <view>
<view class="btn-view">
            <view class="btn-view-con" v-for="(item,index) in btn_arr" :key="index" v-if="userInfo.is_root == 1 ? true : index == '1' ? false : true">
                <view class="circle_view_con">
                    <view class="circle_view" :style="{'width':(windowWidth*0.5/3)+'px','height': (windowWidth*0.5/3)+'px','margin':(windowWidth*0.25/3-2)+'px','margin-bpttom': (windowWidth*0.1/3)+'px'}" @tap="routingJump(index)">
                        <image :src="item.img_src"></image>
                    </view>
                </view>
                <text>{{item.text}}</text>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
                    btn_arr : [{
                //bindthing : "switchTo",
                img_src : "/static/my/fengrenji.png",
                text : "text_machine"
            },
            {
                //bindthing : "navigatorToStaffPage",
                img_src : "/static/my/users.png",
                text : "text_staff"
            },
            {
                //bindthing : "",
                img_src : "/static/my/jk_service.png",
                text : "text_service"
            }]
                };
    },
  methods: {
    routingJump:function(index){
            if (index == "0") {
                console.log("界面跳轉(zhuǎn)至機(jī)器主頁(yè)");
                uni.switchTab({
                    url:'/pages/machine/machine'//機(jī)器主頁(yè)
                })
            } else if (index == "1") {
                console.log("界面跳轉(zhuǎn)至員工界面");
                uni.navigateTo({
                    url:'/pages/employee/employee'//員工界面
                })
            }
            
        },
  }
}
</script>

1.2 scroll-view

(1)eg1

<!-- 通過(guò)點(diǎn)擊方式(選項(xiàng)卡的方式代碼負(fù)責(zé)且應(yīng)用卡)切換分類(lèi)(高效簡(jiǎn)單)  掌握css動(dòng)態(tài)樣式追加小技巧 -->
<view class="grace-header-cate">
    <scroll-view class="grace-tab-title grace-center" scroll-x="true" id="grace-tab-title">
        <view v-for="(cate,index) in categories" :key="index" :data-cateid="cate.cateId" :data-index="index" 
            :class="[cateCurrentIndex == index ? 'grace-tab-current' : '']" @tap="tabChange">{{cate.name}}
        </view>
    </scroll-view>
</view>

2. 基礎(chǔ)內(nèi)容

2.1 icon

請(qǐng)參考uni-app組件使用注意中的icon的使用說(shuō)明部分罗珍。

2.2 text

3. 表單組件

3.1 button

<button type="primary" form-type="submit">添加</button>

3.3 form

(1)eg1

<!-- 輸入?yún)^(qū) -->
<form @submit="submit">
    <view class="inputArea">
        <view class="addImg" @tap="addImg">+圖片</view>
            <view class="addText">
                <textarea name="artText" maxlength="-1" v-model="inputContent" placeholder="請(qǐng)輸入文本"></textarea>
                <button type="primary" form-type="submit">添加</button>
            </view>
    </view>
</form>

3.4 input

  • value :輸入框的初始內(nèi)容
  • placeholder :輸入框?yàn)榭諘r(shí)占位符(引用國(guó)際化文本問(wèn)題)
  • name : 該屬性的作用,uni-app官網(wǎng)無(wú)該屬性
  • v-model :動(dòng)態(tài)綁定數(shù)據(jù)
  • @input:當(dāng)鍵盤(pán)輸入時(shí)泼差,觸發(fā)input事件不撑,event.detail = {value}
  • @blur:輸入框失去焦點(diǎn)時(shí)觸發(fā)押桃,event.detail = {value: value}
    (1)eg1
<input type="text" v-model="title" placeholder="請(qǐng)輸入標(biāo)題"/>

(2)eg2

<input type="text" class="weui-search-bar__input" :placeholder="T_D.keyword" placeholder-style="color:#e2e2e2" v-model="keyword"/>

(3)eg3

<input type="text" class="weui-search-bar__input" :placeholder="T_D.keyword" v-model="keyword" @blur="inputBlur" @input="inputTyping" />
<view class="weui-icon-clear" v-if="keyword.length > 0" @tap="clearInput">
    <icon type="clear" size="14"></icon>
</view>

(4)eg4
小程序:

<view class="weui-cell__bd">
     <input class="weui-input" type="text" placeholder="{{T_D.pleaseEnterGroupName}}" name="name" value="{{name}}">{{name}}</input>
 </view>

修改語(yǔ)法:

<view class="weui-cell__bd">
    <input class="weui-input" type="text" :placeholder="T_D.pleaseEnterGroupName" name="name" :value="name">{{name}}</input>
</view>

備注:input 為單標(biāo)簽,值只能寫(xiě)在里面.繼續(xù)修改:

<view class="weui-cell__bd">
    <input class="weui-input" type="text" :placeholder="T_D.pleaseEnterGroupName" name="name" :value="name"></input>
</view>

雙向綁定:v-model和:value的效果一致.

<view class="weui-cell__bd">
    <input class="weui-input" type="text" :placeholder="T_D.pleaseEnterGroupName" name="name" v-model="name"></input>
</view>

3.6 picker

  • mode :
  • :range :mode為 selector 或 multiSelector 時(shí)捷绒,range 有效
  • :value :value 的值表示選擇了 range 中的第幾個(gè)(下標(biāo)從 0 開(kāi)始)
  • @change :value 改變時(shí)觸發(fā) change 事件先壕,event.detail = {value: value}
  • :range-key :當(dāng) range 是一個(gè) Array 時(shí)涯冠,通過(guò) range-key 來(lái)指定 Object 中 key 的值作為選擇器顯示內(nèi)容
    (1)eg1
<picker @change="bindPickerChange" :value="index" :range="array">
        <view class="uni-input">{{array[index]}}</view>
</picker>

(2)eg2

<!-- 選擇分類(lèi) -->
<view class="art-cate">
    <view>文章分類(lèi)</view>
    <view class="">
        <picker mode="selector" :range="caties" @change="cateChange">
            <view>{{caties[currentCateIndex]}}</view>
        </picker>
    </view>
</view>

3.6 picker-view

(1)eg1

<modal title="{{T_D.pleaseChoosePosition}}" hidden="{{modalHidden}}" confirm-text="{{T_D.confirm}}" cancel-text="{{T_D.cancel}}" bindconfirm="modalBindaconfirm" bindcancel="modalBindcancel">
       <picker-view indicator-style="height: 50px;border-top:1px solid green;border-bottom:1px solid green;" style="width: 100%; height: 200px;text-align:center;" range="{{positionArray}}" value="{{value}}" bindchange="bindChange">
              <picker-view-column>
                      <view wx:for="{{positionArray}}" wx:key="{{item.id}}" style="line-height: 50px">{{item.text}}</view>
              </picker-view-column>
      </picker-view>
</modal>

改為:

<modal :title="T_D.pleaseChoosePosition" :hidden="modalHidden" :confirm-text="T_D.confirm" :cancel-text="T_D.cancel" @confirm="modalBindaconfirm" @cancel="modalBindcancel">
    <picker-view  indicator-style="height: 50px;border-top:1px solid green;border-bottom:1px solid green;" style="width: 100%; height: 200px;text-align:center;" :value="value" @change="bindChange">
        <picker-view-column>
            <view v-for="(item,index) in positionArray" :key="item.id" style="line-height: 50px">{{item.text}}</view>
        </picker-view-column>
    </picker-view>
</modal>

備注:語(yǔ)法修改完成后,運(yùn)行時(shí)列表內(nèi)容不顯示,只有一個(gè)空的列表架子.
modify1:

<modal :title="T_D.pleaseChoosePosition" :hidden="modalHidden" :confirm-text="T_D.confirm" :cancel-text="T_D.cancel" @confirm="modalBindaconfirm" @cancel="modalBindcancel">
    <picker-view  indicator-style="height: 50px;border-top:1px solid green;border-bottom:1px solid green;" style="width: 100%; height: 200px;text-align:center;" :value="value" @change="bindChange">
        <picker-view-column>
            <view class="item" v-for="(item,index) in positionArray" :key="item.id">{{item.text}}</view>
        </picker-view-column>
    </picker-view>
</modal>
.item{
    line-height: 50px;
    height:50px !important;
}

備注:style提取出來(lái)后,列表內(nèi)容成功顯示,但change事件異常,列表無(wú)法正臣鹋玻滑動(dòng).
modify2:

<modal :title="T_D.pleaseChoosePosition" :hidden="modalHidden" :confirm-text="T_D.confirm" :cancel-text="T_D.cancel" @confirm="modalBindaconfirm" @cancel="modalBindcancel">
    <picker-view v-if="!modalHidden" indicator-style="height: 50px;border-top:1px solid green;border-bottom:1px solid green;" style="width: 100%; height: 200px;text-align:center;" :value="value" @change="bindChange">
        <picker-view-column>
            <view class="item" v-for="(item,index) in positionArray" :key="item.id" style="line-height: 50px">{{item.text}}</view>
        </picker-view-column>
    </picker-view>
</modal>

注意:添加 v-if="!modalHidden" 所有問(wèn)題都解決.

3.11 textarea

<textarea :value="item.content" placeholder="" v-model="artList[index].content"></textarea>
<textarea name="artText" maxlength="-1" v-model="inputContent" placeholder="請(qǐng)輸入文本"></textarea>

4. 導(dǎo)航-navigator

(1)eg1

<!-- 文章內(nèi)容區(qū) -->
        <view class="grace-news-list">
            <block v-for="(item,index) in artList" :key="index">
                <!-- 一張圖 -->
                <navigator v-if="item.art_content.length < 3" open-type="navigate" :url="'../info/info?artid=' + item.art_id">
                    <view class="grace-news-list-img-news">
                        <view class="grace-news-list-title-main">{{item.art_title}}</view>
                        <view class="grace-news-list-img-big">
                            <image :src="item.art_content[0]" mode="widthFix"></image>
                        </view>
                    </view>
                </navigator>
                <!-- 三張圖 -->
                <navigator v-if="item.art_content.length >= 3" :url="'../info/info?artid=' + item.art_id">
                    <view class="grace-news-list-img-news">
                        <view class="grace-news-list-title-main">{{item.art_title}}</view>
                        <view class="grace-news-list-imgs">
                            <view class="imgs"><image :src="item.art_content[0]" mode="widthFix"></image></view>
                            <view class="imgs"><image :src="item.art_content[1]" mode="widthFix"></image></view>
                            <view class="imgs"><image :src="item.art_content[2]" mode="widthFix"></image></view>
                        </view>
                    </view>
                </navigator>
            </block>
        </view>

5. 媒體組件

5.3 image

  • src:圖片資源地址
  • mode:圖片裁剪、縮放的模式
  • lazy-load:圖片懶加載
    (1)eg1
<image :src="item.content" :data-index="index" mode="widthFix" @tap="removeImg"/>

(2)eg2

<!-- 文章內(nèi)容區(qū) -->
        <view class="grace-news-list">
            <block v-for="(item,index) in artList" :key="index">
                <!-- 一張圖 -->
                <navigator v-if="item.art_content.length < 3" open-type="navigate" :url="'../info/info?artid=' + item.art_id">
                    <view class="grace-news-list-img-news">
                        <view class="grace-news-list-title-main">{{item.art_title}}</view>
                        <view class="grace-news-list-img-big">
                            <image :src="item.art_content[0]" mode="widthFix"></image>
                        </view>
                    </view>
                </navigator>
                <!-- 三張圖 -->
                <navigator v-if="item.art_content.length >= 3" :url="'../info/info?artid=' + item.art_id">
                    <view class="grace-news-list-img-news">
                        <view class="grace-news-list-title-main">{{item.art_title}}</view>
                        <view class="grace-news-list-imgs">
                            <view class="imgs"><image :src="item.art_content[0]" mode="widthFix"></image></view>
                            <view class="imgs"><image :src="item.art_content[1]" mode="widthFix"></image></view>
                            <view class="imgs"><image :src="item.art_content[2]" mode="widthFix"></image></view>
                        </view>
                    </view>
                </navigator>
            </block>
        </view>

6. 進(jìn)度條-progress

<view class="weui-progress">
       <view class="weui-progress__bar">
              <progress percent="{{item.use_time}}" stroke-width="3" />
        </view>
 </view>

修改語(yǔ)法:

<view class="weui-progress">
    <view class="weui-progress__bar">
        <progress :percent="item.use_time" stroke-width="3" />
    </view>
</view>

其他

注意事項(xiàng).PNG

可參考小程序轉(zhuǎn)uni-app語(yǔ)法差異

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末绽慈,一起剝皮案震驚了整個(gè)濱河市恨旱,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌坝疼,老刑警劉巖搜贤,帶你破解...
    沈念sama閱讀 216,591評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異钝凶,居然都是意外死亡仪芒,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,448評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)耕陷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)掂名,“玉大人,你說(shuō)我怎么就攤上這事哟沫〗让铮” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,823評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵嗜诀,是天一觀的道長(zhǎng)猾警。 經(jīng)常有香客問(wèn)我,道長(zhǎng)隆敢,這世上最難降的妖魔是什么发皿? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,204評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮拂蝎,結(jié)果婚禮上穴墅,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好玄货,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,228評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布皇钞。 她就那樣靜靜地躺著,像睡著了一般誉结。 火紅的嫁衣襯著肌膚如雪鹅士。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,190評(píng)論 1 299
  • 那天惩坑,我揣著相機(jī)與錄音掉盅,去河邊找鬼。 笑死以舒,一個(gè)胖子當(dāng)著我的面吹牛趾痘,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蔓钟,決...
    沈念sama閱讀 40,078評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼永票,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了滥沫?” 一聲冷哼從身側(cè)響起侣集,我...
    開(kāi)封第一講書(shū)人閱讀 38,923評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎兰绣,沒(méi)想到半個(gè)月后世分,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,334評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡缀辩,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,550評(píng)論 2 333
  • 正文 我和宋清朗相戀三年臭埋,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片臀玄。...
    茶點(diǎn)故事閱讀 39,727評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡瓢阴,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出健无,到底是詐尸還是另有隱情荣恐,我是刑警寧澤,帶...
    沈念sama閱讀 35,428評(píng)論 5 343
  • 正文 年R本政府宣布累贤,位于F島的核電站募胃,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏畦浓。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,022評(píng)論 3 326
  • 文/蒙蒙 一检疫、第九天 我趴在偏房一處隱蔽的房頂上張望讶请。 院中可真熱鬧,春花似錦、人聲如沸夺溢。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,672評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)风响。三九已至嘉汰,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間状勤,已是汗流浹背鞋怀。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,826評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留持搜,地道東北人密似。 一個(gè)月前我還...
    沈念sama閱讀 47,734評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像葫盼,于是被迫代替她去往敵國(guó)和親残腌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,619評(píng)論 2 354

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