可运行完整代码

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://unpkg.com/vue@next"></script>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
  <div id="hello-vue">
    {{ message }}
  </div>
</body>
<script>
// 函数柯里化
// url 不变, 参数变化
function get(url) {
  return function(params) {
    return axios.get(url + params)
      .then(res => {
        console.log('res ', res.data)
      })
  }
}
// 
const HelloVueApp = {
  data() {
    return {
      message: 'Hello Vue!!'
    }
  },
  mounted() {
    const baseUrl = 'https://www.fastmock.site/mock/320dcea3c1fbc2abb8bc0f60c25569f7/api'
    // axios.get(`${baseUrl}/blog/1`)
    //   .then((res) => {
    //     console.log('res ', res.data)
    //   })
    const getBlog = get(`${baseUrl}/blog/`)
    getBlog(1)
    getBlog(2)
  },
}
// 
Vue.createApp(HelloVueApp).mount('#hello-vue')
</script>
</html>

TaoWu
15 声望2 粉丝

引用和评论

0 条评论