Vue Data Interaction instance code and vue interaction instance

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.