Vue Data Interaction instance code and vue interaction instance
Interaction in vue (ajax, jsonp)
Vue also has data interaction like ajax and jsonp, to obtain data from the server, but his framework does not have such a method, need a new little thing called vue-resouce.js address: https://github.com/pagekit/vue-resource/blob/master/README.md
<Meta charset = "UTF-8"> <title> Document </title> <script type = "text/javascript" src = "vue. js "> </script> <script type =" text/javascript "src =" vue-resource.js "> </script> <style type =" text/css "> </style>
$ Http is similar to ajax. It can this. $ http. get this. $ http. post, and jsonp can complete cross-Origin data retrieval.
<Div id = "app"> <button @ click = "get () "> button </button> </div> <script type =" text/javascript "> var vm = new Vue ({el: '# app', data :{}, methods: {get: function () {this. $ http. jsonp ('https: // sug.so.360.cn/suggest'{word:' B '}). then (function (res) {alert (res. data. s) ;}, function (res) {alert (res. status) ;}}}}); </script> </body>
Baidu pull-down example for cross-Origin data retrieval:
<Meta charset = "UTF-8"> <title> Document </title> <script type = "text/javascript" src = "vue. js "> </script> <script type =" text/javascript "src =" vue-resource.js "> </script> <style type =" text/css "> * {margin: 0; padding: 0 ;}. bg {width: 200px; line-height: 30px ;} </style>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.