12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title>axios 获取数据</title>
- <meta name="description" content="">
- <meta name="keywords" content="">
- <link href="" rel="stylesheet">
- </head>
- <body>
- <div id="app">
- <button @click='getAjaxInfo()'>按钮</button>
- <span> {{msg}}</span>
- </div>
- <script type="text/javascript" src='../js/vue.min.js'></script>
- <script type="text/javascript" src='../js/axios.min.js'></script>
- <script type="text/javascript">
- //没有后台数据,所以会报错
- var app = new Vue({
- el: '#app',
- data: {
- msg: '我是数据'
- },
- methods: {
- getAjaxInfo: function() {
- axios('ajax_info.txt').then(function(res) {
- this.msg = res.data;
- }.bind(this)).catch(function(err) {
- console.log(err);
- })
- }
- }
- });
- </script>
- </body>
- </html>
|