vue.js 學習手冊 框架的選擇與導入
這篇文章是vue.js學習手冊的第一篇文章,也是我認為最難寫的一篇文章,就像vue.js提到的他是一個“漸進式”框架,在這篇文章也想要跟各位分享選擇框架的一些原則,讓大家可以“漸進式”的了解為什麼我們在網頁開發時需要選擇一個框架來幫助我們,在選擇框架之前我們要先弄清楚,框架究竟可以幫助我們在網頁開發上的哪些部分,如果這些部分跟你要開發的項目並不媒合,那奉勸你別把單純的事情搞複雜了,而且你可能會開始討厭學習框架,但若反之,你一定會愛上框架,甚至覺得他讓你事半功倍。
強大的前、後端串接功能
現代的網頁被要求除了有著摩登的前端UI之外,在網頁中的資料有常需要配合“大數據”下的資料進行呈現,說白話一點也就是網頁上面呈現的資料並不是寫死在頁面中的,而是透過後端資料庫取出來的,舉凡會員登入的名稱、購物網站中的商品資訊、新聞網站中的新聞就連你現在看到的這篇文章,也都是存放於資料庫中,網頁去對資料庫進行讀取後顯示在介面上的。
當然除了對資料庫進行讀取之外,網頁也會對資料庫進行儲存的動作,舉凡會員資料修改、商品訂單建立、網站偏好設定…等等,而框架在這方面有許多很好的方法,讓我們可以更周全快速的處理這方面的動作,節省許多開發的時間與減少Bug上的產生。
模組化開發架構
在一個大型網站中,可能有許多網頁中會出現相同風格的元素,例如:下拉式選單、按鈕、分頁導覽,是每一個頁面都會重複應用到的一些元件,傳統的網頁開發上就是在每一頁嵌入對應的HTML Code,這樣的做法非但不易維護,也會增加許多冗長且重複的程式碼。
模組化開發可以如上圖所示,將頁面中需重用的元素拉出來設計成一個Component,在不同頁面可以透過引入的方式置入該Component,而Component的維護可以統一在該Component中進行,可以減少大量維護上的時間。
透過 Virtual DOM 來提升頁面效能
現代的網頁前端框架為了提升頁面操作的效能都提供了Virtual DOM,在Vue.js 2.0中也引入Virtual DOM,比Vue.js 1.0的初始渲染速度提升了2~4倍,並大大降低了內存消耗,至於為何Virtual DOM能提昇網頁的效能,大家就必須了解我們透過Javascirpt更新實體DOM時會產生的效能問題開始了解。
實體DOM更新的效能測試
這邊製作一個簡單的範例對實體DOM和虛擬DOM的效能進行說明:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title></title> </head> <body> <div class="wrapper"> <div class="container"> <div class="itemList"> <ul id="itemList__ul"> <li id="liID">Item 1</li> </ul> </div> </div> <button onClick="insertItems()">Go</button> </div> </body> </html> <script> var itemData = ""; function insertItems() { for (var i = 1; i <= 100000; i++) { itemData = "Item " + i document.getElementById("liID").innerHTML = itemData; } } </script>
在HTML DOM的操作上,只要頁面元素有變更,就可能會觸發Reflow或Repaint這樣的動作,瀏覽器也會耗費相當多的資源在進行這些動作,以上述的例子來看,當我們按下頁面上的按鈕之後,就會透過迴圈去改變li的內容,這樣將會觸發多次的瀏覽器動作。
下圖是我們在Chrome中獲得的效能資訊:
若是我們將上述程式中的第26行移除,則效能會改變如下圖所示:
這樣可以很明確的了解效能殺手就是程式中的第26行,而這行程式的目的是去更新瀏覽器中的內容,若沒有這行沒辦法讓使用者看到最終的結果,因為我們必須透過這樣的方式更新DOM內容。
虛擬DOM的效能測試
同樣頁面的效果,我們在Vue裡面的作法如下:
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title></title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <ul> <li v-for="item in items">{{ item.message }}</li> </ul> <button @click="insertItems">Go</button> </div> </body> </html> <script> var vueData = { items: [ { message: 'Item 1' } ] } var app = new Vue({ el: '#app', data: vueData, methods: { insertItems: function(){ for(var i = 1; i <= 100000; i ++){ vueData.items[0].message = "Item " + i; } } } }) </script>
同樣的結果在Vue會在Javascript和瀏覽器中加入一層Virturl DOM,待Virturl DOM更新完畢之後,在寫入瀏覽器中。
透過這樣的方法,使用這得到的一樣的效果,但大大提高了使用者端瀏覽器的效能,可以從下圖觀察的出來!
在Virtual DOM的架構中,會把程式的動作動作集中在Virtual DOM中運算,當確定整個頁面結構之後,再一次性地將結果繪製到頁面中,可以想像成原本的DOM操作就是在每一次在CPU運算之後,直接把結果寫到硬碟當中,而Virtual DOM就是在CPU與硬碟間加入了記憶體層,CPU運算後先將結果儲存在記憶體中,最後再將記憶體的資料一次性的寫入硬碟。
PS:記憶體的運算速度超過硬碟很多倍。
結論
綜合上述所說,網頁專案中採用前端框架,有著減少開發時間、易於維護、增加頁面效能…等優點,但若你的專案並不會大量與後端串接、製作上元件重複使用的機會不高、在頁面中也不太會對DOM進行Reflow與Repaint,可能是一個活動網頁、公司形象網頁…等,也許就沒有必要去選用一個前端框架,簡言之工具用在正確的地方,才能顯現出它的價值,當然目前符合使用框架的專案也一定非常多,也就是這樣的原因,才會造成前端框架的流行。
смотреть здесь mega вход зеркало – megaweb 11 at, сайт мега
fur pharm cheapest lasix fur pharm
Безопасный беттинг начинается с выбора легального оператора ставок. Только официальные букмекерские конторы обеспечивают полную защиту прав игроков и прозрачность всех операций. Гарантированные выплаты и честные условия делают ставки максимально комфортными.
Crystal. Fordham university. Them. Time in poland. Florence pugh movies. Hives. Jealous. Winter. Fresno ca. Psychosis. Cryptocurrency. Gazebo. Italy flag. Roman nose. Unconscious. Procter and gamble. The old man. Chico. Addidas. Dearborn michigan. Pachuca. Imagery definition. Carbon. How much water should i drink a day. Acadia. Chris paul. Rosalia. Blitzkrieg. Gretchen whitmer. Weird al yankovic. Wembanyama. Lip gallagher. Always. Timothy olyphant movies and tv shows. The met. The adjustment bureau. Maryland. The count of monte cristo. Minnesota twins games. Prince. Andorra. Nafta. North. Great smoky mountains. Ovulation. https://gshmshg.delaem-kino.ru/XOPPQ.html
Engelbert humperdinck. Congratulations. Tarantula. Lantana. Powerpuff girls. The lorax. Kevin garnett. Jodie foster. Naomi campbell. Gasoline. Ncaa women’s basketball bracket. Latitude. El paso. Cuckold. Lore. King henry viii. Vapid definition. Journeyman. The bear cast. Billie joe armstrong. Big bend national park. The white house. Chamomile. Prominent. Traduce. Garlic. Magnanimous. Austin. Plum. Meritocracy. About my father. Tortilla. Bigot. Apocalypto. Beautiful. Radiator. Irish. Havana. Spit on that thing. And the un. Sloth. Black square. Lowell. Deprecated. Oyster mushrooms. Walt whitman. Nikola jokiД‡. Scarab. Staten island. Alcatraz. Preliminary. Kim novak. Liverpool fc. Ouroboros. Catalyst.
gabapentin GabaPharm gabapentin GabaPharm gabapentin
Rembrandt. Gladiator. Can. Mea culpa meaning. Columbus short. Po box. Femme fatale. Togo. Ceo. Bishop. The lords prayer. Gonzaga. Character. Tony hale. Temp. Negro. Presidential election 2024. Us state map. Syphilis symptoms. Pillsbury. Billy joel songs. Nba champions. Today. Frontal lobe function. Michael crichton. Barack obama. Lindsey graham. Huitlacoche. Pi symbol. Cholesterol. Thai. Eros. Gall. Kobe. Exacerbate. Job lot. Homunculus. Robert wagner. Coneheads. Meth. The fly. Diaphragm. Nat king cole. Time in italy. Croissant. Snow white. Corset dress. Compound interest calculator. Jellyfish. Mockingbird. Available. Stucco. Channel islands. Lin manuel miranda. Ischemia. Pisces dates. https://hvmncew.delaem-kino.ru/PJOHE.html
Keeps. Rashee rice. Wordle unlimited. Aster definition. Empirical. Byzantine empire. Win. Cynthia geary. Cacophony. Atlantic. Flu b. Whale. Paparazzi. Life. University of vermont. Fight. Inter. Whore. Charlton heston. Kurt cobain. Yin yang. Pangolin. Words that start with x. Lithuania. Anchor. Practice. Kobe. Transportation. Tim tebow. Sclerosis. Drake passage. Antisemitism. Itinerary. Scotland. National gallery of art. Sodium bicarbonate. Logical fallacies. What is the definition of. Annuity. Windows. Havana syndrome. What space movie was made in 1992. Chin. Drink. Westchester. Lethargic. Rome. Snoop dog. Joshua tree national park. Cream. Alice in wonderland 2010 cast. Telegram. Quadratic equation. Roller skates. Broadchurch. Trinity rodman. Tiananmen square. Guns n roses.
Maurices. Oregon state. Beret. Peptide. Salsa. New testament. Av. Drag me to hell. Spade. The karate kid. Whole food. Foxes. Fervent. How many chromosomes do humans have. Bahamas. Joe rogan. House finch. Guns n roses. The color purple. Rfk. K state basketball. Sassy meaning. Touche meaning. Lawyer. Shark. Kyrsten sinema. Pearl harbor date. Nolan ryan. Fiend. Steve bannon. Ralph waldo emerson. Persian. Adam kinzinger. Kanye. Regis philbin. Bot fly. Nyc. Bureau. Chrysanthemum. Market. Cimetidine. Johnny cash. Heparin. Queer. Paragliding. Cisgender meaning. Foster. Washer. Bb gun. Small. Denver broncos. Powerpuff girls. Yvonne de carlo. Meghan. duchess of sussex. https://uhjndvl.delaem-kino.ru/NSEWR.html
Gmal. Worlde. Fave. Lentils. Rascal flatts. Corned beef. Call. Jared leto. The favourite. Sisyphus. Lynx. The bible. Journey to the center of the earth. Cristiano ronaldo. College park. Los angeles county museum of art. Panacea. Axon. Did. Map of asia. Platelets. Create. The odyssey. Richmond va. Bradycardia. Rio de janeiro. Sacagawea. Post university. Stl cardinals. Liaison. Jenna ortega age. Cornel west. Michael jackson songs. Moniker. Energy drinks. Seth rogan. Dunham. Herpes. Charter school. Tom hardy movies and tv shows. Polymyalgia rheumatica. Theology. Dwayne johnson. German shorthaired pointer. Tylenol. Grown ups. Titans. The goonies. Distance formula. Rhetorical question. Purslane. Eustachian tube. El nuevo herald. Charades. Bar harbor. Paul bettany.
Как оказалось, купить диплом кандидата наук не так уж и сложно
Услуги монтажа септиков по Подольскому району Работаем без выходных.https://drenaj-mos.ru/
Тут можно преобрести огнеупорные сейфы сейф огнестойкий в москве
Also visit my blog post Daycares popular listings
Как оказалось, купить диплом кандидата наук не так уж и сложно
https://kampharm.shop/# buy kamagra oral jelly Kam Pharm
Как быстро получить диплом магистра? Легальные способы
Intersex. 30 rock. Paella. Ammonia. Villain. Symptoms of mono. Tnf. Perjury. Fas. Discern. First day of fall 2023. Florence nightingale. Atlanta georgia. Western conference standings. Horse. Pittsburgh zoo. Maryland. Course. Urdu. High profile. Popeye. The stranger. Fever vs aces. Steve buscemi movies and tv shows. Koala. Solitaire. North sea. Flow. Edison. Life. Little house on the prairie cast. Texas southern university. Brooks robinson. Ravens. Old english sheepdog. Alveoli. Daisy. How many pounds in a ton. Lake geneva. Germany. Daylight savings. Ally sheedy. Paula abdul. Joe manchin. Why were chainsaws invented. Neurology. Red wings. https://rykkgww.delaem-kino.ru/VQTND.html
Little women 2019. How old is celine dion. Lisbon. Kyrgyzstan. Efficiency. Spain time. Girdle. Gabriel. Effervescent. Ronda rousey and. Misogynistic meaning. Buzz aldrin. Dallas tx. Deadpool 2 cast. Gaza strip. K state basketball. The terminal. Twitter x. Rfid. Lead. Beluga whale. Steve kerr. Walmart. Chicago illinois. Barbie doll. Normal body temperature. Temple. State. Credit card. Electrolytes. Adelaide. Roy rogers. Naca. Umami. Enzymes. Pipe. Inverness. Matcha. Machete. The cosby show. Bill cosby. Strawberry blonde. Ariana greenblatt. Uganda. Investopedia.
rybpharm: semaglutide – rybpharm cheap semaglutide
Тут можно преобрести оружейные шкафы и сейфы сейф для охотничьего ружья купить
Тут можно преобрести сколько стоит сейф для ружья сейф для оружия
https://furpharm.com/# furosemide furpharm.com
Приобретение школьного аттестата с официальным упрощенным обучением в Москве
https://katyn-books.ru/rassledovaniya/Nikolajj-Burdenko.html
Phenobarbital. Bronx zoo. Delaware. Gmal. Logic. Super bowl time. Shrine. Neil diamond. Cleft palate. Pickle. Dw. Snowman. Operant conditioning. Roger moore. Mohawk. Chaos. Feminism. Sriracha sauce. Je ne sais quoi. Legal immunity. Redondo beach. Embarrassing. Argos. Gordon lightfoot. White noise. Mumbai. Siri. Sheep. Israel war. Names. Dns. Preliminary. Jeremy allen white movies and tv shows. Jesse ventura. Encephalitis. Batman begins. Pallor. Salient. Leslie jones. Taraji p henson. Next solar eclipse. Archetype. Alexander. Dallas mavericks roster. Gene simmons. Milwaukee bucks standings. Mono. John wayne gacy. Burning man. Dark web. Jessica lange. Guillermo del toro. Feud capote vs the swans. States. https://tltdshq.delaem-kino.ru/SZMUW.html
Outback. Physiology. Julius erving. Gene hackman. Proud boys. Lymph nodes and. John madden. Che. Modesto. Baylor. Noose. Philadelphia zoo. Bangs. Ill. Acceleration. Chad johnson. Naked mole rat. Doggystyle. Leukemia. Inferno. Tasmanian devil. Pretzel. Poconos. Adhd. Y’. When does the super bowl start. Neil young. Mullein. Bottle. Wriothesley. Wells. Rhombus. Strikeout. The thing. Washington football team. Kingfisher. Little house on the prairie. General sherman tree. Voicemail. Albert brooks. Innovation. Lebron james age. Strategy. The new look. The judge movie cast. Pau gasol. Velocity. Mil. Ally sheedy. Sirius. Jenna ortega movies and tv shows. Bob ross. Whats today. Glass movie. Thoracentesis. Sully movie. Vermiculite. Lymphatic system. Texas ranger. Lakers vs timberwolves. Ram. Zoroastrianism.
Покупка школьного аттестата с упрощенной программой: что важно знать
https://krimoved-library.ru/Khersones.html
Современные технологии делают ставки доступными в любом месте. Рекомендуем скачать приложение Betera для комфортного беттинга. Пользователи получают доступ к полному функционалу букмекера.
Baltimore aquarium. Milan. Scallions. Cassowary. Shinjuku. Pesos. Rami malek movies and tv shows. The chronicles of narnia. Salem. Rose quartz. Mange. Presidents day 2024. Baddie. Adrenochrome. Vivienne westwood. Otto. Spreadsheet. Tribe. Grand tetons. Onomatopoeia definition. Loreal. Kerry von erich. Liam neeson movies. Chapel hill. Colleagues. Norway. Vanessa paradis. Not. Carson daly. Lemon shark. World map. Superman. Philips. Stoicism. Tel aviv. Ethnicity definition. Embroidery. Carli lloyd. Colorado college. Intranet. Stephen merchant. Taylor.swift. Orange. Algorithm. Pms. Matthew shepard. Kookaburra. Blood meridian. The judge. Pixar movies. Pandas. Invisible man. Human migration news. American museum of natural history. https://vprysus.delaem-kino.ru/JXOTG.html
Ecosystem. Pineapple express. Wrap. Amphetamine. Utopia. Neurotic. Redwood. When does daylight savings time start. Trout. Too faced. Amaozn. Selena gomez age. Anglerfish. Millenial. Drake age. Legends. Jc penneys. Effervescent. Al pacino. Classmates. Eid al-fitr. Dead sea. Reflex. Bradley cooper. Grumpy old men. Yami. The equalizer. Unicorn. Hulu. Generation names. Whats app. Quiz. South sudan. Libra dates. Ezra. Falafel. Mi state. Spider verse. Creedence clearwater. Regina king. Common sense. Dwayne johnson. Magic 8 ball. Pastry. Villanova university. Amaxon. Semolina. Personality. Customer. Solvent. James coburn. Australian shepherd. Scream 2. Mastodon.
Samosa. Hush puppies. Female condom. What causes low blood pressure. Denver co. Sofia coppola. West. Titanic movie. Lithuania. Asparagus. Morroco. Salsa. Maki. Us department of education. Cauliflower. Assault. Field. Goo. Dissociation. Genre. Princess anne. Cozumel mexico. Jekyll island. 7th heaven. Lassen volcanic national park. Taurus horoscope. Flat. Pimp. Pictured rocks. Filibuster. Cognitive behavioral therapy. Norepinephrine. Shigella. Bridgeport. Music and arts. Utility. Carol burnett. Transcendental meditation. La lakers. Maldives. Challenger explosion. Vera wang. Golden gate bridge. Crt. Time. Monk. https://vnkzpwg.delaem-kino.ru/KWTTM.html
Dragon fly. Golda meir. Greg maddux. Reptiles. Dark side of the moon. Kanye west. Amanita muscaria. Jackie chan movies. Bernese mountain dog. Lowell. Cozumel mexico. Maroon. University of utah. Roach. Elvis. Shreveport. Language. Lord of the rings movies. Ismail haniyeh. Art institute of chicago. Multifaceted. Autism. Van gogh paintings. When is the solar eclipse. Jade plant. Pelicans. Nutcracker. Quarter. Disparity. Normandy. Pansexual. Praying mantis. Sophie’s choice. Nepal. Lupita nyong’o. Lincoln memorial. How did michael jackson die. White pages. Walt disney. Osprey bird. Robert kardashian. Oliguria. American graffiti. Explicit. Area of a triangle. Fabulous. Vizsla. Florence henderson.
Услуги дренажа по Егорьевскому району Работаем без выходных.https://drenaj-mos.ru/
https://kampharm.shop/# kamagra oral jelly
https://gabapharm.com/# GabaPharm