【发布时间】:2017-08-25 03:19:47
【问题描述】:
我们的 django 服务器是我们的 API 以及操作后端。我正在通过编写一个慢慢替换现有操作后端的 Vue SPA 来改进我们的操作后端。
我是前端,有点迷失在复杂的 Django 配置中。有人可以为这个问题提出一个明智的解决方案吗?
我希望从静态文件夹中提供应用程序,并已设置:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, '../console/dist'),
)
这可行,我可以在查看源代码时看到我的代码,但只能在http://localhost:8000/static/console/index.html
1) 这不起作用,因为作为 SPA,Vue 需要控制路由。在 Django 方面,我怎样才能让/static/console/* 使用我的 Vue 应用程序?在 Vue 端,我在 Webpack 和 Vue-router 中需要配置什么?
2) 尽管我可以看到我编译的应用程序源,但我得到了错误:
Creating Application Cache with manifest http://localhost:8000/static/appcache/manifest.appcache
index.html:1 Application Cache Checking event
index.html:1 Application Cache Downloading event
index.html:1 Application Cache Progress event (0 of 7) http://localhost:8000/favicon.ico
index.html:1 Application Cache Error event: Resource fetch failed (4) http://localhost:8000/favicon.ico
index.html:1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
这很奇怪,因为http://localhost:8000/favicon.ico 是一个有效的 URL。我感觉这也是 Webpack 的问题。
我有什么选择?
【问题讨论】:
标签: django webpack vue.js vue-router