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數據 只要 異步請求數據 那么不是同源就是 跨域 ,跨域就得去 服務器 配置 允許跨域請求 通過