使用Ajax库-axios

知识点

  • 为网页增加远程数据存取能力(Ajax)
  • HTTP库axios(浏览器 or Node.js)

axios:Promise based HTTP client for the browser and node.js

https://github.com/axios/axios

实战演习

  1. $ cd myweb
  2. $ npm install --save --save-exact axios vue-axios
  3. #注册组件
  4. $ nano main.js
  5. ...
  6. import axios from 'axios'
  7. import VueAxios from 'vue-axios'
  8. Vue.use(VueAxios, axios)
  9. ...
  10. #各个组件
  11. $ nano HelloWorld.vue
  12. ...
  13. <pre>{{content}}</pre>
  14. ...
  15. export default {
  16. name: "HelloWorld",
  17. data() {
  18. return {
  19. content: ""
  20. };
  21. },
  22. mounted() {
  23. this.axios.post("http://api.komavideo.com/news/list").then(body => {
  24. this.content = body.data;
  25. });
  26. }
  27. };
  28. ...

VS Code workspace setting

纠正VSCode-vetur插件的4空格格式化问题

  1. {
  2. "prettier.tabWidth": 4
  3. }

课程文件

https://gitee.com/komavideo/LearnVueJS2

小马视频频道

http://komavideo.com