vue_post_get獲取數據

1引入vue-resource
    import VueResource from 'vue-resource'
    Vue.use(VueResource);

2php

    postGetListJson(newIndex){
        let url=`http://api.v.com/index.php?r=v1/user/test`
        Vue.http.get(url).then((response) => { 
            alert(response);
        });
    },

 

 php服務端添加函數vue

3json

   public function beforeAction($action)
    {
        header('Access-Control-Allow-Origin:'.\Yii::$app->params[ 'clientDomain']);
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }

 

 

 

 

可選  4api

location /rest {
add_header Access-Control-Allow-Origin "*";
...
}

 

 

其餘app

// global Vue object
Vue.http.get('/someUrl', [data], [options]).then(successCallback, errorCallback);
Vue.http.post('/someUrl', [data], [options]).then(successCallback, errorCallback);

// in a Vue instance
this.$http.get('/someUrl', [data], [options]).then(successCallback, errorCallback);
this.$http.post('/someUrl', [data], [options]).then(successCallback, errorCallback);

 

new Vue({
    ready() {
      // GET request
      this.$http.jsonp('/someUrl', {xxx:"xxxx"})
        .then(function (response) {
          console.log(response.data)
      }, function (response) {
          // error callback
      });
    }
})
相關文章
相關標籤/搜索