Vue中的前后台交互

忘是亡心i 2022-11-15 12:56 278阅读 0赞

先安装axios

  1. npm install axios

然后在vue页面中进行编码:

  1. import axios from 'axios';
  2. export default {
  3. name: 'App',
  4. components: {
  5. },
  6. data: function(){
  7. return {
  8. my_pics: []
  9. }
  10. },
  11. methods: {
  12. getPicList(pic_dir) {
  13. const path = 'http://127.0.0.1:5000/folder/'+pic_dir;
  14. axios.get(path, null, { params: { root:pic_dir}})
  15. .then((res) => {
  16. this.my_pics = res.data;
  17. })
  18. .catch((error) => {
  19. // eslint-disable-next-line
  20. console.error(error);
  21. });
  22. }
  23. },
  24. created() {
  25. },
  26. }

发表评论

表情:
评论列表 (有 0 条评论,278人围观)

还没有评论,来说两句吧...

相关阅读

    相关 前后交互

    [通过AngularJS实现前端与后台的数据对接(一)——预备工作篇][AngularJS]       最近,笔者在做一个项目:使用AngularJS,从而实现前端与后