近些天有接觸到uni-app框架,使用HBuilderX軟件進行編譯,能生成多端項目文件,如微信、百度、支付寶小程序及Android和ios端,記錄遇到的問題
#ifdef:if defined 僅在某平臺存在 #ifndef:if not defined 除了某平臺均存在 如:只在微信小程序中才執行的代碼 // #ifdef MP-WEIXIN uni.getSystemInfo({ success: res => { this.navHeight = `${res.statusBarHeight + 46}px`; } }); // #endif
/* 調用相機代碼 */ uni.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['camera'], success: res => { const tempFilePaths = res.tempFilePaths[0]; } });
在使用這個滾動到對應元素時,前端的渲染須要進行必定的延遲纔可以定位到對應的id前端
<scroll-view class="scrollView" scroll-with-animation scroll-x :scroll-into-view="'cate_'+scrollIntoCate"> <view :id="'cate_'+item.id" v-for="item in cateList" :key="item">{{item.title}}</view> </scroll-view> /* 在js中 */ onLoad(options) { setTimeout(() => { this.scrollIntoCate = options.id; }, 400); }, .scrollView{ /* 如果橫向滾動定位,應設置寬度 */ width: 100%; /* 如果豎向滾動定位,則應設置高度 */ height: 100%; }
若是你是豎向的滾動定位,則你必須設置高度,橫向定位的話,應該設置寬度,不然沒法定位元素
使用後綴名爲nvue的文件vue
{ "path": "pages/video/video", "style": { "app-plus": { /* 子窗體定位 */ "subNVues":[{ "id": "videoChild", "path": "pages/video/index", "style": { "position": "absolute", "left": "0px", "bottom": "0px", "width": "750px", "height": "100px", "background": "transparent" } }] } } }
將要設置子窗體的頁面放入同一個文件夾,在index.nvue中,文字的放置應該是在text中,在pages.json中也應寫死寬度,不能使用百分比,支持flex佈局,同時,在index.nvue中你要是想設置背景色,則應該使用background-colorios
/* list.vue文件 */ this.$nextTick(() => { uni.$emit('children', Object); }) /* index.nvue文件 */ <div class="shopInfo" id="videoChild"> <text class="shopName">@{{shopname}}</text> </div> created() { uni.$on('children', (data) => { this.$nextTick(() => { console.log(data); }) }) }, /* 在頁面銷燬前移除監聽事件 */ beforeDestroy(){ uni.$off('children'); },
<view class="listItem" v-for="item in imageList" :key="item.id"> <image class="itemImg" :src="item.img" :style="{ animationDuration: item.index }"></image> </view> this.imageList.push(...res.data.result.list); for (let i = 0; i < this.imageList.length; i++) { if (!this.imageList[i].index) { this.imageList[i].index = parseInt(35 + Math.random() * (10 - 5)) + 's'; } } .itemImg { width: 1000upx; height: 318upx; animation: imageMove linear infinite alternate; } @keyframes imageMove { 0% { transform: translateX(0); } 50% { transform: translateX(-30%); } 100% { transform: translateX(0); } }
let cateList = []; this.cateLength = cateList.length; let temporaryList = []; if (cateList.length > 10) { for (let i = 0; i < cateList.length; i += 10) { let list = cateList.slice(i, 10 + i); temporaryList.push(list); } this.cateList = temporaryList; }
正在努力學習中,若對你的學習有幫助,留下你的印記唄(點個贊咯^_^)