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--- 一点车项目  连接数据库 服务端配置

原文地址:https://www.cnblogs.com/reeber/p/10730643.html