如何将Vue.js与Flask结合使用?

烧瓶 Vue.js

理查德小胖Harry

2020-03-19

我想同时使用Vue.js和Flask:Vue.js用于动态前端,而Flask用于后端。我怎样才能做到这一点?

第2404篇《如何将Vue.js与Flask结合使用?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
小宇宙小哥 2020.03.19

使用vue-cli或Webpack时,可以简化过程。只需创建

vue.config.js在您的Vue项目中,请参阅:Vue配置

module.exports = {
    outputDir: "../dist",

    // relative to outputDir
    assetsDir: "static" 
};

然后配置烧瓶应用程序:

app.py

from flask import Flask, render_template

app = Flask(__name__,
            static_folder = "./dist/static",
            template_folder = "./dist")


@app.route('/')
def index():
    return render_template("index.html")

注意,在烧瓶static_foldertemplate_folder不能相同。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android