vue.jsbuild之后是在django下面运行的,首页用一个djangoview渲染,通过context给它传递了参数,到了index.html中拿到参数后,怎样进一步传递到app里面?classIndexPageView(TemplateView):defget_context_data(self,**kwargs):context=super().get_context_data(**kwargs)context['now']=timezone.now()returncontexturlpatterns=[url(r'^admin/',admin.site.urls),url(r'^api/',include('api.urls')),url(r'^$',IndexPageView.as_view(template_name="index.html")),]contextfromdjango:{%templatetagnow%}
2 回答
慕的地10843
TA贡献1785条经验 获得超8个赞
官方论坛里帮你找了个回答:HTML:
JS:newVue({el:'#my-target-element',template:'Justanexamplewith{{varName}}',data:{varName:null},beforeMount:function(){this.varName=this.$el.attributes['data-var-name'].value;},});原解答点这里