鍍金池/ 問(wèn)答/HTML/ 急??!vue-resource無(wú)法提交post數(shù)據(jù) 路徑404

急??!vue-resource無(wú)法提交post數(shù)據(jù) 路徑404

在網(wǎng)上看了個(gè)視頻,上面用的是vue2.0之前的版本,所以配置vue-resource的get和post都是在build.js下的dev-server.js中,而我用的是vue2.0之后的新版本,所以文件目錄中沒(méi)有dev-server.js文件。

我在網(wǎng)上查了資料,新版本vue的dev-server.js配置要在webpack.dev.conf.js中配置,如圖1和圖2,都是在webpack.dev.conf.js中進(jìn)行配置的。

圖1圖1
圖2圖2

存放模擬數(shù)據(jù)的db.json文件放在圖3的位置

圖3圖3

方法代碼如下

getPrice(){
    let reqParams = {
    goodsname: this.$root.bestsellgoods[this.productid].goodsname,
    buyType: this.$root.bestsellgoods[productid].goodsclassify,
    price: this.$root.bestsellgoods[this.productid].presentprice,
    buyNumber: this.buyNum
    }
    this.$http.post('/api/getPrice', reqParams)
    .then((res) => {
        console.log(res)
        //this.price = res.data.amount
    })
},

結(jié)果執(zhí)行方法的話,訪問(wèn)不到db.json文件中的getPrice中的數(shù)據(jù)

圖4圖4

路徑問(wèn)題怎么改??求指教

回答
編輯回答
朕略傻

可以嘗試換成axios,vue-resources早已經(jīng)不再維護(hù)了,不建議使用。

2017年6月12日 08:34
編輯回答
心沉

本地json放在static目錄下 就好了

2017年1月29日 18:40