element-ui 本地化使用教程詳解
起因:
用 element-ui 時,本人是沒有安裝其它環(huán)境,而是直接用鏈接引入,這個帶來的問題是,每次打開網(wǎng)頁都很慢,于是想本地化,但是發(fā)現(xiàn)只是下載兩個引入的 js 和 css 是不夠的,很多功能會無法使用,打開 DevTools 發(fā)現(xiàn)是還有別的資源本地沒有。
再次前往官網(wǎng),找到下載頁面,結(jié)果發(fā)現(xiàn)并沒有給直接的下載鏈接。。沒辦法了,自己寫個腳本來下載。最后成功離線化。
下載后在 html 中引入:
<!--<link rel="stylesheet" >--> <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css" rel="external nofollow" > <!--<script src="https://unpkg.com/element-ui/lib/index.js"></script>--> <script src="element-ui/lib/index.js"></script>
下載腳本:
臨時起意做的,代碼里面可能會有些瑕疵,但是不影響使用,本人已經(jīng)成功下載并使用。
路徑可以自己更改,注意不要從 Windows 資源管理器復(fù)制,Linux 系統(tǒng)當(dāng)我沒說。
package com.ycr; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; public class Main { static String fileP = "C:\\Users\\YCR\\Desktop\\element-ui\\"; // 不要從資源管理器復(fù)制,有的字符會有問題,導(dǎo)致無法創(chuàng)建文件 static String urlP = "https://unpkg.com/browse/element-ui@2.12.0/"; static String urlF = "https://unpkg.com/element-ui@2.12.0/"; public static void main(String[] args){ try { GetPage(""); } catch (Exception e) { e.printStackTrace(); } } static void GetPage(String after) throws Exception { System.out.println(urlP + after); new File(fileP + after).mkdir(); HttpURLConnection http = (HttpURLConnection) (new URL(urlP + after)).openConnection(); http.setRequestMethod("GET"); http.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3562.0 Safari/537.36"); http.connect(); if(http.getResponseCode() == 200) { InputStream inputStream = http.getInputStream(); byte [] buffer = new byte[1024]; ArrayList<byte []> byteList = new ArrayList<>(); ArrayList<Integer> byteLength = new ArrayList<>(); int length; int totalLength = 0; while( (length = inputStream.read(buffer)) != -1 ) { byteList.add(buffer); byteLength.add(length); totalLength += length; buffer = new byte[1024]; } http.disconnect(); byte [] all; all = new byte[totalLength]; totalLength = 0; while(byteList.size() != 0) { System.arraycopy(byteList.get(0), 0, all, totalLength, byteLength.get(0)); totalLength += byteLength.get(0); byteList.remove(0); byteLength.remove(0); } String content = new String(all, StandardCharsets.UTF_8); all = null; content = content.split("tbody")[1]; String [] us = content.split("href=\""); for(int i = 1; i < us.length; i ++) { String href = us[i].split("\"", 2)[0]; if(href.equals("../")) { continue; } if(href.charAt(href.length() - 1) == '/') { GetPage(after + href); } else { GetFile(after + href); } } } else { GetPage(after); } } static void GetFile(String url) throws Exception{ System.out.println(url); HttpURLConnection http; http = (HttpURLConnection) (new URL(urlF + url)).openConnection(); http.setRequestMethod("GET"); http.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3562.0 Safari/537.36"); http.connect(); if(http.getResponseCode() == 200) { InputStream inputStream = http.getInputStream(); byte [] buffer = new byte[1024]; ArrayList<byte []> byteList = new ArrayList<>(); ArrayList<Integer> byteLength = new ArrayList<>(); int length; int totalLength = 0; while( (length = inputStream.read(buffer)) != -1 ) { byteList.add(buffer); byteLength.add(length); totalLength += length; buffer = new byte[1024]; } http.disconnect(); byte [] all; all = new byte[totalLength]; totalLength = 0; while(byteList.size() != 0) { System.arraycopy(byteList.get(0), 0, all, totalLength, byteLength.get(0)); totalLength += byteLength.get(0); byteList.remove(0); byteLength.remove(0); } File f = new File(fileP + url.replaceAll("/", "\\\\")); f.createNewFile(); FileOutputStream fos = new FileOutputStream(f, false); fos.write(all); fos.flush(); fos.close(); } else { GetFile(url); } } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用vue-router切換頁面時,獲取上一頁url以及當(dāng)前頁面url的方法
這篇文章主要介紹了使用vue-router切換頁面時,獲取上一頁url以及當(dāng)前頁面url的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05vue 使用html2canvas將DOM轉(zhuǎn)化為圖片的方法
這篇文章主要介紹了vue 使用html2canvas將DOM轉(zhuǎn)化為圖片的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09vue實現(xiàn)左右伸縮方式(el-drawer自定義位置展開收縮)
這篇文章主要介紹了vue實現(xiàn)左右伸縮方式(el-drawer自定義位置展開收縮),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07利用Vue.js+Node.js+MongoDB實現(xiàn)一個博客系統(tǒng)(附源碼)
本文主要介紹了利用Vue.js+Node.js+MongoDB實現(xiàn)一個博客系統(tǒng),這個博客使用Vue做前端框架,Node+express做后端,數(shù)據(jù)庫使用的是MongoDB。實現(xiàn)了用戶注冊、用戶登錄、博客管理、文章編輯、標(biāo)簽分類等功能,需要的朋友可以參考學(xué)習(xí)。2017-04-04淺談Vue使用Elementui修改默認(rèn)的最快方法
這篇文章主要介紹了淺談Vue使用Elementui修改默認(rèn)的最快方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12