计算机网络/计算机科学与应用/系统/运维/开发

vue-axios-get获取数据


axios-get




$db = @mysqli_connect('localhost','root','root','test') or die('无法链接服务器');     

mysqli_query($db,"set names utf8");     

$select_sql = "select * from test";     

$result = mysqli_query($db,$select_sql);     

$arr = array();    

 while ($row = $result->fetch_assoc()) {         

        $arr[] = $row;     }     echo(json_encode($arr));          <html>     <head>     <meta charset="UTF-8">     <title>Document</title> <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script> <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script> </head> <body>     <div id="app">         <table border="1px" cellspacing="0">             <tr>                 <th>id</th>                 <th>name</th>             </tr>             <tr v-for="item in data">                 <td>{{ item.id  }}</td>                 <td>{{ item.name }}</td>             </tr>         </table>     </div>         <script>         new Vue({             el:'#app',             data(){                return{                   data:{}                 }             },             mounted:function(){                  var _this = this             axios.get('vue2.php')             .then(function (res) {                 _this.data = res.data;                  console.log(res.data)             }, function (error) {                              })           }         })     </script> </body> </html>


vue axios

人各有命,但命运也从来不是随机发牌,而是每个人主动选择的结果。

评论

^