I'm trying to get data from Django to Vuetemplate variables.
views.py
def index(request):
myvar = 1
return render(request, 'index.html',{'myvar':myvar})
in index.html
<span> {{ myvar }} </span>
Is working, and shows 1, but how can i get this 1/myvar to data inside of the vue instance?
var app = new Vue({
el: "#app",
data: {
// here i need the data/value of myvar
}
CodePudding user response:
You can grab the value via params of route
var app = new Vue({
el: "#app",
data: {
// here i need the data/value of myvar
myvar: this.$route.params.myvar
}
CodePudding user response:
var app = new Vue({
el: "#app",
data: {
myvar: '{{ myvar }}' //myvar comes from django urls.py
}
Works for me, this.$route.params.myvar doesn't cause im not using vuerouter.