用的是django+vue做后端和前端,我想在渲染首页的时候传递一些后端的配置给前端页面:
class HomePageView(TemplateView): template_name="index.html" def get_context_data(self, **kwargs): context = super(HomePageView, self).get_context_data(**kwargs) context['arg1'] = "12345" context['arg2'] = "67890" return context urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', HomePageView.as_view()), ]
但是前端vue build出来的的index.html很简单,如何才能让vue里面的js访问后端给它的context参数?
<body> <div id=app>{{ arg1 }}</div> <script type=text/javascript src=/static/js/manifest.ab01a7ddcd228431bc0f.js></script> <script type=text/javascript src=/static/js/vendor.4be9c4044c880f3a85ed.js></script> <script type=text/javascript src=/static/js/app.11129f6d90cce37c7348.js></script> </body>
函数式编程
相关分类