javascript - 在 django 模板中使用来自 node_modules 的 vuelidate
问题描述
我使用 Vue 来使用 API,但从未在 Django 模板中使用过。我想使用该Vuelidate
包进行表单验证,但在导入validationMixin
他们的文档中指定时遇到了一些问题:import { validationMixin } from 'vuelidate'
.
我目前正在从 CDN 导入 Vue.js。
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
我正在将 vuelidate 的路径添加到我的静态文件中。
# settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'staticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'node_modules', 'vuelidate', 'dist'),
]
当我的 Django 模板被加载时,我得到SyntaxError: import declarations may only appear at top level of a module
(Firefox) 和Uncaught SyntaxError: Unexpected token {
(Chrome)
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="module" src="{% static 'vuelidate.min.js' %}"></script>
<script>
import { validationMixin } from 'vuelidate'
const app = new Vue({
delimiters: ['[[', ']]'],
el: '#app',
data: {
test: 'Hello'
}
})
</script>
我添加type="module"
到脚本标签,但结果是TypeError: Error resolving module specifier: vuelidate
(Firefox)和Uncaught TypeError: Failed to resolve module specifier "vuelidate". Relative references must start with either "/", "./", or "../".
(Chrome)
我在这里想念什么?
解决方案
推荐阅读
- r - 用于工具包文档的 docker:`docker export` 不包括所有层?
- java - setDescriptionTextSize(float size) 无法解析方法 MPAndroidChart
- python - 尝试 pd.concat 时,我得到了意外的 NaN 值。如何处理?PCA 与 T-SNE
- visual-studio-2017 - 使用 OData v4 Web API 脚手架时出错
- git - Github:git子模块更新挂起,不克隆
- .net - Gitlab CI 错误:作业失败:退出代码 1
- c++ - 线性规划:模约束
- docker - Artifactory 6.0.3,无法使用 Tomcat/repo 登录到 docker
- ios - 自动布局约束和堆栈视图
- angular - Angular 5 ngModel ngFor 不使用 trackBy