!!!欢迎来到我的博客站点~

Vue--- 一点车项目 连接数据库 数据使用

Vue--- 一点车项目  连接数据库 数据使用

后台服务器 返回数据 处理

created 这个钩子在实例被创建之后被调用:

  async created(){
    // 分类 catelist
    {
      let res=await fetch(SERVER + 'api/catelist');
      let arr=await res.json();
      this.cate_list = arr;
    }
    // 省份
    {
      let res=await fetch(SERVER + 'sql/sheng');
      let arr=await res.json();
      this.sheng = arr;
      // 省份一查询完 就吧省份里面的第一个的 id给到 ccur——pro  显示第一个
      this.cur_pro = this.sheng[0].id;
    }
    // 城市
    {

      let res=await fetch(SERVER + `sql/city/${this.sheng[0].id}`);
        let arr=await res.json();
        this.citys = arr;

    }
  },

读取 数据库 js文件   用fetch  异步读取,返回值 处理为 json数据        只要 异步请求数据 那么不是同源就是 跨域 ,跨域就得去 服务器 配置 允许跨域请求 通过

<<<<Vue--- 一点车项目  连接数据库 服务端配置

posted @ 2019-04-18 16:45  Haisen'Blogs  阅读(2696)  评论(0编辑  收藏  举报

reeber

开车啦

1
2
3
4
5
/* 看板娘 */