小編給大家分享一下vue中分離css的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
vue中分離css的方法:首先在vue文件中設(shè)置“<style src="./record.scss"></style>”;然后新建index.js文件;最后建立相對(duì)應(yīng)的html、js和css文件即可。
在正常的創(chuàng)建和引用vue文件都是html、css、js三者在一起的,這樣寫(xiě)起來(lái)雖然方便了,但是頁(yè)面比較大或者代碼比較多的情況下,即使使用組件有時(shí)代碼也比較多,簡(jiǎn)單來(lái)說(shuō)查找不變不利于編程,大的來(lái)說(shuō)影像優(yōu)化性能。將代碼中的html、css、js分離出來(lái)是個(gè)很好的選擇。
首先,在 .vue文件中設(shè)置如下:
<template src="./record.html"></template> <script src="./record.js"></script> <style src="./record.scss"></style>
新建index.js文件,如下:
import record from './record.vue'; export default record;
建立相對(duì)應(yīng)的record.html、record.js、record.scss的文件,就可以了,拿.js來(lái)說(shuō):
// -- NAME -- const name = 'record'; // -- DATA -- const data = function () { return { }; }; // -- COMPUTED -- const computed = { }; // -- COMPONENTS -- const components = { } // -- WATCH -- const watch = { }; // -- METHODS -- const methods = { }; // -- HOOKS -- function mounted() { } // == EXPORT == export default { name: name, data: data, components: components, computed: computed, watch: watch, methods: methods, mounted: mounted };
另一種方法可以直接引用:
<template> <div>html</div> </template> <script src="./***.js"></script> <style src="./***.css"></style>
形式多樣,但根本思想都是分離獨(dú)立文件,引入加載
看完了這篇文章,相信你對(duì)vue中分離css的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
本文題目:vue中分離css的方法-創(chuàng)新互聯(lián)
文章路徑:http://jinyejixie.com/article10/psido.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、網(wǎng)站改版、網(wǎng)站導(dǎo)航、服務(wù)器托管、手機(jī)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容