-1

My expectation is that when the button is clicked by the user, the data will appear according to the active category, if the sealin of these two things displays an error in the template

methods: {
  fetchCategory() {
    const API_URL_Categories = 'https://fakestoreapi.com/products/categories'
    fetch(API_URL_Categories)
      .then(response => response.json())
      .then(data => {
        this.categories = data
        //  kategori aktif ada dalam daftar kategori yang valid
        //  (English comment:) The active category is in the list of valid categories
        if (!this.categories.includes(this.categoryActive)) {
          this.categoryActive = this.categories[0]
        }
        // Ambil data produk berdasarkan kategori aktif
        // (English comment:) Retrieve product data by active category
        this.fetchProducts()
      })
      .catch(error => {
        console.error('Error fetching categories:', error)
      })
  }
}
Luuk
  • 12,245
  • 5
  • 22
  • 33
  • Welcome to Stack Overflow, please read [How to Ask](https://stackoverflow.com/help/how-to-ask) before posting your questions. I've attempted to give a more accurate title related to the actual technical issue and fixed your text formatting. Also, [do not post code as images](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors/285557#285557). – yoduh Aug 03 '23 at 16:46
  • I'm sorry, it's Kuh's fault, for the future I won't do it again – galangFirstDev Aug 03 '23 at 16:51
  • Can you help me? – galangFirstDev Aug 03 '23 at 16:52
  • 1
    Who is `Kuh` ? You question is not clear, and I think my English is OK (for the reading part) – Luuk Aug 03 '23 at 16:53
  • Can you help me? – galangFirstDev Aug 03 '23 at 17:00
  • I'm sorry, English is not good – galangFirstDev Aug 03 '23 at 17:00
  • We can't help you with _"an error in the template"_ if you don't show the error. I suggest you create a *runnable* [mcve] in codesandbox.io or a similar service, making sure the error you're seeing on local is reproduced in the minimal example. Without it, chances you'll get a useful answer are quite slim. – tao Aug 03 '23 at 17:12
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 04 '23 at 19:33
  • thanks for the input , i will correct my mistake – galangFirstDev Aug 05 '23 at 03:41

0 Answers0