近些天有接触到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; }
正在努力学习中,若对你的学习有帮助,留下你的印记呗(点个赞咯^_^)