小编Phu*_*ang的帖子

Golang html模板无法在html文件中调用javascript文件

在HTML文件中调用它后,我将React应用程序与Webpack捆绑在一起.但是,当我使用Golang和html/template查看HTML文件时,它会出错.

我的HTML文件:index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Note App</title>
    </head>
    <body>
        <div id="root"></div>
        <script src="public/bundle.js"></script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)



我的Golang文件:index.go

package main

import (
    "net/http"
    "html/template"
    "path/filepath"
)

func handle(w http.ResponseWriter, r *http.Request) {
    fp := filepath.Join("views", "index.html")
    t := template.Must(template.ParseFiles(fp))
    t.Execute(w, nil)
}

func main() {
    http.HandleFunc("/", handle)
    http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud)

javascript go

3
推荐指数
1
解决办法
1255
查看次数

标签 统计

go ×1

javascript ×1