I am new to vue js. I am making shopping web app.
Frontend request product list to backend server when product page created() and It will be write to data.
This is my data()
name: "Product",
data () {
return {
products : []
}
}
and This is fetch() code
fetch('http://test.exper.cc:3001/api/v1/'+ tag +'/@public/products',
{"method":"GET"})
.then(
function(response) {
response.json().then(function (obj) {
this.products = obj.data
}
);
Backend server returns
[{"id": 1,"name": "상품명", "desc": "상품명 이라는 상품입니다.","image": "https://image.com/image2.png", "subproducts": [{"name": "1일", "prices": {"DEFAULT": 1000}, "desc": "해당 상품은 1일 상품 입니다.", "stock_count": 10}, {"name": "7일", "prices": {"DEFAULT": 6000}, "desc": "해당 상품은 7일 상품 입니다.", "stock_count": 12}]}, {"id": 2,"name": "상품명2", "desc": "상품명2 이라는 상품입니다.", "image": "https://image.com/image.png", "subproducts": [{"name": "1일", "prices": {"DEFAULT": 1000}, "desc": "해당 상품은 1일 상품 입니다.", "stock_count": 1}, {"name": "7일", "prices": {"DEFAULT": 6000}, "desc": "해당 상품은 7일 상품 입니다.", "stock_count": 294}, {"name": "30일", "prices": {"DEFAULT": 25000}, "desc": "해당 상품은 30일 상품 입니다.", "stock_count": 19}]}]
My program makes error console log
I just need to put json to this.products data. Can you help me?
I googled this issue but it don't helps me. Sorry for my bad english ;(