美文网首页
学会开发灵活的网页(Javascript)

学会开发灵活的网页(Javascript)

作者: syeturing | 来源:发表于2017-04-16 23:10 被阅读12次

3.7、使用 JSON 和 AJAX传递api数据(使用vue和reqwest实现用其它网站获取数据并传入本网站(My height is 189 cm))

3.2
前后端通过json进行交互
vue.js代替templetes

UC截图20170417234705.png UC截图20170417234154.png
UC截图20170417235153.png 3.2删广告

3.2实战删广告


1
2

3.3

添加script 尾端添script,script内部 UC截图20170418203928.png
UC截图20170418210546.png
UC截图20170418211507.png
有需要时,将style移至body中

在body里写{{ article.title }}即可看到This is a title

UC截图20170418211847.png
UC截图20170418212327.png
UC截图20170418212438.png UC截图20170418183533.png
UC截图20170418201757.png UC截图20170419211014.png
UC截图20170419212435.png UC截图20170419235030.png

3.4

UC截图20170420002104.png
UC截图20170420002121.png

script中的True,第一个字母不大写(true)才能发挥效果

            <div class="ui action fluid input">
                <input type="text" placeholder="添加新任务" v-model="message">
                <button class="ui icon basic button">
                    <i class="plus icon" style="color:#666666" v-on:click="AddNew(message)"></i>
                </button>
            </div>
                methods:{
                    AddNew:function(message){
                        this.tasks.push({todo:message,yes:true,show:true})
                    }
                },

要绑定v-model才能传数据

UC截图20170419211014.png
UC截图20170419212435.png
UC截图20170419235030.png
UC截图20170420185224.png
UC截图20170420185952.png
UC截图20170420195843.png
UC截图20170422131842.png
UC截图20170422131905.png
UC截图20170422132834.png
UC截图20170424180043.png
UC截图20170424180143.png
UC截图20170424181926.png

models-views-(json)-vue.js
model-(序列化)-字典-json-views
1.创建views的同级文件api.py,import在models里需要的类,引用rest_framework相关文件,在settings的installed apps里添加rest_framework


序列化器

fields='__all__'

编写一个视图(定义函数)


UC截图20170424232218.png

urls添加
{% verbatim %}
django别渲染{}
{% endverbatim %}

get-查
post-增
put-改
delete-删

在settings的installed apps里添加rest_framework.authtoken(make migrations)
token 不能加在data,而是加在header中


感谢老师,感谢老师呀 UC截图20170425220657.png
UC截图20170425221214.png
UC截图20170425222901.png
UC截图20170425234339.png
UC截图20170426233739.png
UC截图20170426234104.png
UC截图20170426234354.png
UC截图20170426234811.png
UC截图20170426235211.png
UC截图20170426235755.png
UC截图20170424232218.png
UC截图20170424234818.png

相关文章

网友评论

      本文标题:学会开发灵活的网页(Javascript)

      本文链接:https://www.haomeiwen.com/subject/yjszattx.html