ajax

196 阅读1分钟
  1. get

<template>
  <div id = "app">
    {{info}}
  </div>
</template>

<script>
import Axios from 'axios'
export default {
  name: 'app',
  data () {
    return {
      info: ''
    }
  },

  mounted () {
    Axios
      .get('/api/try/ajax/json_demo.json',{params : {a:1,b:2}})
      .then(response => (this.info = response))
      .catch(function (error) { // 请求失败处理
        console.log(error)
      })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

  1. post


<template>
  <div id = "app">
    {{info}}
  </div>
</template>

<script>
import Axios from 'axios'
export default {
  name: 'app',
  data () {
    return {
      info: ''
    }
  },

  mounted () {
    Axios
      .post('/api/try/ajax/demo_test_post.php', {name: '菜鸟教程', url: 'http://www.runoob.com'})
      .then(response => (this.info = response))
      .catch(function (error) { // 请求失败处理
        console.log(error)
      })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>