admin管理员组文章数量:1287776
I'm trying to make django & Vue work together even though they share the same {{ X }} template syntax.
I know that from django 1.5 we can use the {% verbatim %}
tag. So I thought I could use django templates as usual and in the section where I need VUE to take over I would just use the {% verbatim %} tag. However instead of loading my vue data django loads the {{ variable }}
.
For example my django code looks something like this:
{% verbatim %}
<div id='sessions'>
<h2>{{message}}</h2>
</div>
{% endverbatim %}
And in my app.js file I have:
var sessions = new Vue({
el: '#sessions',
data: {
message: 'Hello Vue!'
}
})
But instead of rendering Hello Vue!
it renders {{message}}
The console doesn't show any error and vue loads correctly otherwise.
How I can make the two work together? Ideally without the need to change the vue.js {{}} syntax.
I'm trying to make django & Vue work together even though they share the same {{ X }} template syntax.
I know that from django 1.5 we can use the {% verbatim %}
tag. So I thought I could use django templates as usual and in the section where I need VUE to take over I would just use the {% verbatim %} tag. However instead of loading my vue data django loads the {{ variable }}
.
For example my django code looks something like this:
{% verbatim %}
<div id='sessions'>
<h2>{{message}}</h2>
</div>
{% endverbatim %}
And in my app.js file I have:
var sessions = new Vue({
el: '#sessions',
data: {
message: 'Hello Vue!'
}
})
But instead of rendering Hello Vue!
it renders {{message}}
The console doesn't show any error and vue loads correctly otherwise.
How I can make the two work together? Ideally without the need to change the vue.js {{}} syntax.
Share Improve this question asked Apr 22, 2017 at 21:34 CostantinCostantin 2,6568 gold badges34 silver badges52 bronze badges1 Answer
Reset to default 13You can change Vue's interpolation delimiters to whatever you want.
var sessions = new Vue({
el: '#sessions',
delimiters: ['${', '}'],
data: {
message: 'Hello Vue!'
}
})
That way you can use whatever your framework needs.
Edit
It turned out in this case, @Costantin had more than one div#sessions on the page.
本文标签: javascriptMaking Django amp Vuejs work together withverbatim Stack Overflow
版权声明:本文标题:javascript - Making Django & Vue.js work together with {% verbatim %} - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741282398a2370082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论