0

I am building a new app with vuejs 2 and got that error

ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/components/Customers.vue Module build failed: SyntaxError: C:/Users/Men'm Elkatan/projects/vuecustomers/src/components/Customers.vue: this is a reserved word (17:6)

I used "this" before but didn't get that error expect today. Here's my code

<script>
export default {
  name: 'customers',
  data () {
    return {
      customers: []
    }
  },
  methods: {
    fetchCustomers({
      this.$http.get('http://slimapp/api/customers')
        .then(function(response) {
          this.customers = JSON.parse(response.body);
        });
    })
  },
  created: function(){
    this.fetchCustomers();
  }
}
</script>

Please!! help

1 Answer 1

1

Your syntax was wrong. It has to be fetchCustomers() { ... }:

<script>
export default {
  name: 'customers',
  data () {
    return {
      customers: []
    }
  },
  methods: {
    fetchCustomers() {
      this.$http.get('http://slimapp/api/customers')
        .then(function(response) {
          this.customers = JSON.parse(response.body);
        });
    }
  },
  created: function(){
    this.fetchCustomers();
  }
}
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

OHH !! Thanks a lot, I didn't care for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.