我正在将一个参数从 Django 传递给我的 html 中的 Vue 方法,如下所示:
# Django view
context = {
'var1': var1,
}
<!-- html -->
<div>
<p>Display var1: {{var1}}</p>
<button @click.prevent="doThis({{var1}})">Do This</button>
</div>
<!-- html result below
Display var1: value_of_var1
-->
上面的工作完美,但是,doThis({{var1}})
给出了一个错误。
// Vue method
method: {
doThis(var1){
console.log(var1)
}
}
我在控制台中得到以下信息:
undefined
...[Vue warn]: Property or method "value_of_var1" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
我究竟做错了什么?
当我将变量传递给方法时,如何得到上述错误?