【发布时间】:2021-04-04 01:45:03
【问题描述】:
我正在使用 Django webpack-loader 在我的 Django 模板中加载 VueJS 组件,基本上我有以下 django 模板:
myTemplate.html(这是我调用 vue 的 Django 模板)
{% load render_bundle from webpack_loader %}
<!DOCTYPE html>
<html lang="en">
{% load static %}
{% block content %}
<head>
...
</head>
<body>
<div id="app">
<div id="someDjangoStuff">
...
</div>
<formComponent></formComponent>
<anotherVueComponent></anotherVueComponent>
<div id="someDjangoStuff2">
...
</div>
</div>
<body>
{% endblock %}
</html>
组件是基本形式,像这样:
<template>
<div>
<form @submit.prevent="formSubmit()">
<input type="text" class="form-control" v-model="amount">
<br>
<input type="text" class="form-control" v-model="price">
<button class="btn btn-primary" >Submit</button>
</form>
</div>
</template>
所以基本上我在这里做的是:
- 我加载了一个 Django 模板
- 我使用
<div id="app"></div>加载 Vue 应用程序 - 我只加载我需要的组件,而不是加载整个 Vue 应用程序,并在
<div id="app"></div>中加载其他 html。
问题是,在我的控制台中,我会收到以下错误:
[Vue warn]: Error compiling template:
Templates should only be responsible for mapping the state to the UI.
我确定这是因为我正在加载 Vue 应用程序,并且在应用程序内部我还加载了其他 html 标记。现在这个错误没有任何影响,这个设置似乎工作正常,但我怀疑这是否是使用 Vue 的正确方法。
- 是否有任何方法可以抑制错误或以其他方式执行此操作而不会出现错误?
- 它会因为这不是我应该使用 Vue 的方式而产生问题吗?
【问题讨论】:
-
您的
someVueComponent和anotherVueComponent代码是什么? -
这是非常基本的组件,只有一些 HTML,但它们没有任何可能导致错误的脚本或东西
-
您的错误似乎是您在不提交更新的情况下操纵状态。你需要阅读更多关于 Vuex 的信息。