In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about WebAssembly + Vugu how to quickly build single-page web application. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Vugu?
Vugu is a Go Library that can easily write HTML, CSS, and Go, which can be compiled and run in a browser using WebAssembly to build your single-page web application (single-page web applications). The name Vugu actually comes from a combination of Vue and Go, and although it seems to be handled in a similar way to js writing Vue, officials are also looking for ways that are more suitable for Go. Hello, World Let's create a Vugu application that can run in a browser with only three files to prepare. But you need to make sure that the Go version is 1.13 or higher.
Create a folder and go.mod
Mkdir vuguTestApp & cd vuguTestApp & go mod init
Create a Vugu component file, root.vugu. Here we implement a click handler and a button to demonstrate some basic functions, from which you can see a little bit of Vue
Test WebAssembly is awesome!
.my-first-vugu-comp {background: # eee;}
Type RootData struct {Show bool} func (data * RootData) Toggle () {data.Show =! data.Show}
c. Create a file devserver.go that provides server. The contents of this file will not be compiled by WebAssembly, but just act as a server. You can notice the + build ignore in the code.
/ / + build ignorepackage main
Import ("log"net/http"os"
"github.com/vugu/vugu/simplehttp")
Func main () {wd, _: = os.Getwd () l: = "127.0.0.1 log.Printf 8844" log.Printf ("Starting HTTP Server at% Q", l) h: = simplehttp.New (wd, true) / / if you have a CSS file, you can quote / / simplehttp.DefaultStaticData ["CSSFiles"] = [] string {"/ my/file.css"} log.Fatal (http.ListenAndServe (l, h))}
d. Execute go run devserver.go
The service will be started, and the operation effect will be the same on Windows,Linux or Mac. After startup, vugu will help you generate a main_wasm.go file.
/ / + build wasm
Package main
Import ("log"os"
"github.com/vugu/vugu")
Func main () {
Println ("Entering main ()") defer println ("Exiting main ()")
RootInst, err: = vugu.New (& Root {}, nil) if err! = nil {log.Fatal (err)}
Env: = vugu.NewJSEnv ("# root_mount_parent", rootInst, vugu.RegisteredComponentTypes ()) env.DebugWriter = os.Stdout
For ok: = true; ok; ok = env.EventWait () {err = env.Render () if err! = nil {panic (err)}}
} / / files that will be compiled to the .wasm suffix (/ / + build wasm)
e. The browser opens http://127.0.0.1:8844/ and you can see the page.
This is how the WebAssembly + Vugu shared by the editor quickly builds single-page web application. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.