正文 776字数 227,478阅读


使用uniapp搭配微信开发者工具自带的骨架屏功能,生成骨架屏

步骤:
1、点击微信开发者工具左下角生成骨架屏
2、回到hbuilderx的项目中,在component中建立一个vue组件,命名为index.vue
3、在index.vue中,把刚刚生成的index.skeleton.wxml和index.skeleton.wxss两个文件复制到index.vue文件里面,注意wxml文件应该放在template标签中,wxss的文件内容应该放在style标签中

4、最重要的一步,需要把index.vue中把标签里面带有(is=""和data-event-opts="")的整个属性删掉
5、在需要用到骨架屏的页面中引入这个组件,注册

<template> <loadingHtml v-if="loadingShow"></loadingHtml> </template> <script> import loadingHtml from '@/components/skeleton/index' export default{ components:{ loadingHtml }, data(){ return { loadingShow:true, }; }, onShow(){ const that=this that.loadingShow=true setTimeout(function(){ that.loadingShow=false },1500) }
Run code
Cut to clipboard