您好,登錄后才能下訂單哦!
使用vue-cli怎么構(gòu)建一個(gè)骨架屏?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
安裝 vue-skeleton-webpack-plugin
npm install vue-skeleton-webpack-plugin
創(chuàng)建文件 skeleton.js和skeleton.vue
skeleton.js
import Vue from 'vue' import Skeleton from './Skeleton.vue' export default new Vue({ components: { Skeleton }, template: '<skeleton />' })
skeleton.vue
我的skeleton.vue不知為何<style>標(biāo)簽寫在外部沒有加載進(jìn)去,故寫到<template>內(nèi)
樣式和模板可以自己修改
<template> <div class="skeleton-wrapper"> <style> .skeleton { padding: 10px; } .skeleton .skeleton-head, .skeleton .skeleton-title, .skeleton .skeleton-content-bottom, .skeleton .skeleton-content { background: rgba(194, 207, 214,.5); background-image: linear-gradient(90deg,rgba(255, 255, 255, 0.15) 25%, transparent 25%); background-size: 20rem 20rem; animation: skeleton-stripes 1s linear infinite; margin: 0 auto 30px; text-align: center; color: darkgray; } .skeleton-head { width: 100px; height: 60px; float: left; } .skeleton-body { margin-left: 110px; } .skeleton-title { width: 90%; height: 60px; line-height: 60px; } .skeleton-content { width: 60%; height: 40px; background: rgba(194, 207, 214,.3)!important; } .skeleton-content-bottom { width: 40%; height: 40px; margin: 0 auto 30px 20%!important; background: rgba(194, 207, 214,.3)!important; } @keyframes skeleton-stripes { from { background-position: 0 0 ; } to { background-position: 20rem 0; } } </style> <header class="skeleton-header"></header> <section class="skeleton-block"> <div class="skeleton"> <div class="skeleton-head"></div> <div class="skeleton-body"> <div class="skeleton-title">加載中</div> <div class="skeleton-content"></div> <div class="skeleton-content-bottom"></div> <div class="skeleton-content"></div> <div class="skeleton-content-bottom"></div> <div class="skeleton-content"></div> <div class="skeleton-content-bottom"></div> <div class="skeleton-content"></div> <div class="skeleton-content-bottom"></div> <div class="skeleton-content"></div> </div> </div> </section> </div> </template> <script> export default { name: 'skeleton' } </script>
在build 目錄下創(chuàng)建 webpack.skeleton.conf.js
'use strict'; const path = require('path') const merge = require('webpack-merge') const baseWebpackConfig = require('./webpack.base.conf') const nodeExternals = require('webpack-node-externals') function resolve(dir) { return path.join(__dirname, dir) } module.exports = merge(baseWebpackConfig, { target: 'node', devtool: false, entry: { //指向自己的skeleton.js路徑 app: resolve('../src/renderer/skeleton/skeleton.js') }, output: Object.assign({}, baseWebpackConfig.output, { libraryTarget: 'commonjs2' }), externals: nodeExternals({ whitelist: /\.css$/ }), plugins: [] })
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。