0

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 ;(

Realtime
  • 11
  • 3
  • Can you also list the whole method which has the fetch() ? It's even better that you list the whole – kevinluo201 Nov 28 '21 at 03:17
  • Don't use `function` if you need to use `this`. Also promises are messy. They are not chained. There shouldn't be nested `then` without a good reason. – Estus Flask Nov 28 '21 at 05:29
  • I am new to JS. It's so messy. I will try to clean my code – Realtime Nov 29 '21 at 13:13

0 Answers0