1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <title></title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <script src="https://unpkg.com/vue/dist/vue.js"></script>
- <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
- <link href="../css/style.css" rel="stylesheet"> </head>
- <body>
- <div id="myApp">
- <input type="button" @click="btnGet()" value="点我异步获取数据(Get)">
- </div>
- <script>
- var vm = new Vue({
- el: '#myApp',
- data: {
- msg: 'Hello World!',
- },
- methods: {
- btnGet: function() {
- //发送get请求
- var data = {
- a: 1,
- b: 2
- };
- this.$http.get('ajax_info.txt', data).then(function(res) {
- document.write("<h3>已经获取到数据:</h3>");
- document.write(res.body);
- }, function() {
- console.log('请求失败处理');
- });
- },
- btnPost:function(){
- //post请求
- }
- }
- });
- </script>
- </body>
- </html>
|