您身边的网站建设专家
成功案例

【建站服务】枝江淘宝装修/枝江京东店铺设计/枝江拼多多网店装修公司/枝江企业网店开通申请-网店装修设计-域名申请

日期: 2022-09-21 03:41:08 浏览数:5


​

上往建站提供服务器空间服务商,百度快照排名,网站托管,百度推广运营,致力于设计外包服务与源代码定制开发,360推广,搜狗推广,增加网站的能见度及访问量提升网络营销的效果,主营:网站公司,百度推广公司电话,官网搭建服务,网站服务企业排名,服务器空间,英文域名等业务,专业团队服务,效果好。


枝江淘宝装修/枝江京东店铺设计/枝江拼多多网店装修公司/枝江企业网店开通申请-网店装修设计

网站建设.png

Vue3 Ajax(axios)

Vue 版本推荐使用 axios 来完成 ajax 请求。


Axios 是一个基于 Promise 的 HTTP 库,可以用在浏览器和 node.js 中。


Github开源地址: https://github.com/axios/axios


安装方法

使用 cdn:


<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

或


<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>

使用 npm:


$ npm install axios

使用 bower:


$ bower install axios

使用 yarn:


$ yarn add axios

使用方法:


Vue.axios.get(api).then((response) => {

  console.log(response.data)

})


this.axios.get(api).then((response) => {

  console.log(response.data)

})


this.$http.get(api).then((response) => {

  console.log(response.data)

})

浏览器支持情况



GET 方法

我们可以简单的读取 JSON 数据:


GET 实例

const app = {

  data() {

    return {

      info: 'Ajax 测试!!'

    }

  },

  mounted () {

    axios

      .get('https://www.runoob.com/try/ajax/json_demo.json')

      .then(response => (this.info = response))

      .catch(function (error) { // 请求失败处理

        console.log(error);

    });


们可以简单的读取 JSON 数据:

GET 实例

const app = {  data() {    return {      info: 'Ajax 测试!!'    }  },  mounted () {    axios      .get('https://www.runoob.com/try/ajax/json_demo.json')      .then(response => (this.info = response))      .catch(function (error) { // 请求失败处理        console.log(error);    });  }} Vue.createApp(app).mount('#app')

尝试一下 »

使用 response.data 读取 JSON 数据:

GET 实例

<div id="app">  <h1>网站列表</h1>  <div    v-for="site in info"  >    {{ site.name }}  </div></div><script type = "text/javascript">const app = {  data() {    return {      info: 'Ajax 测试!!'    }  },  mounted () {    axios      .get('https://www.runoob.com/try/ajax/json_demo.json')      .then(response => (this.info = response))      .catch(function (error) { // 请求失败处理        console.log(error);    });  } } Vue.createApp(app).mount('#app')</script>

尝试一下 »

GET 方法传递参数格式如下:

传递参数说明

// 直接在 URL 上添加参数 ID=12345axios.get('/user?ID=12345')  .then(function (response) {    console.log(response);  })  .catch(function (error) {    console.log(error);  }); // 也可以通过 params 设置参数:axios.get('/user', {    params: {      ID: 12345    }  })  .then(function (response) {


枝江淘宝装修/枝江京东店铺设计/枝江拼多多网店装修公司/枝江企业网店开通申请-网店装修设计


上往建站提供搭建网站,域名注册,官网备案服务,网店详情页设计,企业网店,专业网络店铺管理运营全托管公司咨询电话,服务器空间,微信公众号托管,网页美工排版,致力于域名申请,竞价托管,软文推广,全网营销,提供标准级专业技术保障,了却后顾之忧,主营:虚拟主机,网站推广,百度竞价托管,网站建设,上网建站推广服务,网络公司有哪些等业务,专业团队服务,效果好。

服务热线:400-111-6878 手机微信同号:18118153152(各城市商务人员可上门服务)


全国咨询热线:400-111-6878

地址:全国各地都有驻点商务

Copyright © 2021 通陆科技

网站建设:上往建站