Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How vue files run in browsers

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to run the vue file in the browser, the article is very detailed, has a certain reference value, interested friends must read it!

The vue file runs in the browser: 1, open the cmd command window, and use the cd command to enter the vue project directory containing the vue file; 2, in the project directory, run the command "npm run dev" to start the project; 3, enter "localhost:8080" in the browser address bar.

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

The vue file runs in the browser

Create a new vue file

The official example is as follows. You need to create an index.html file:

Const options = {moduleCache: {vue: Vue}, async getFile (url) {const res = await fetch (url); if (! res.ok) throw Object.assign (new Error (url+''+ res.statusText), {res}); return await res.text () }, addStyle (textContent) {const style = Object.assign (document.createElement ('style'), {textContent}); const ref = document.head.getElementsByTagName (' style') [0] | | null; document.head.insertBefore (style, ref);},} const {loadModule} = window ['vue3-sfc-loader'] Const app = Vue.createApp ({components: {'my-component': Vue.defineAsyncComponent (() = > loadModule ('. / myComponent.vue', options))}, template:''}); app.mount ('# app')

Then you need to create a myComponent.vue file with the following contents:

Hello world

Export default {setup () {console.log ('hello world')}} .title {font-size: 40px; color: red;}

Start the project

In cmd, use the cd command to enter the vue project

In the project directory, run the command npm run dev, which will run our application as a hot load, which allows us to see the effect of the changes in real time without manually refreshing the browser after modifying the code.

Just type localhost:8080 in the browser.

The above is all the contents of the article "how vue files run in browsers". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report