0

I am trying to create multiple plus-minus buttons for my application using VueJS. I have used halfpastfour.am sample code from this link jQuery multiple plus/minus Counter as sample code for my project.

$('.counter-btn').click(function(e) {
  e.preventDefault();
  var $btn = $(this);
  $('#output-' + $btn.data('index')).html(function(i, val) {
    val = val * 1 + $btn.data('inc');
    return (val <= 0 ? '' : '+') + val;
  });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Above is the portion of the code which states there is parsing error: unexpected token under the $('.counter-btn')

Shown like this:

Module Error (from ./node_modules/eslint-loader/index.js):
error: Parsing error: Unexpected token

I tried to resolve by referring to this post ESLint Parsing error: Unexpected token. However I am unable to find any .eslintrc file in my project. Besides that, I appreciate if you can enlighten on why does these parsing errors tend to appear often. Thanks once again.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • The code you've shown does not create that error, as you can see from the snippet I edited in to your question. To check where the error is coming from, double click it in the console. Also check the value from `$btn.data('index')` is valid for use in a jQuery selector – Rory McCrossan Dec 12 '19 at 13:20
  • Are you trying to use this code inside a Vue template? – Gander Dec 12 '19 at 22:28
  • @Gander Yes, I am currently using the code in the vue. However, for the function code above, I am using it under the script column. – Nehemiah Chan Dec 13 '19 at 00:45
  • @RoryMcCrossan Thanks for your reply, I did some searching and realized I didn't import ' import jQuery from 'jquery' global.jQuery = require('jquery') var $ = global.jQuery window.$ = $ window.jQuery = window.$ = jQuery' into main.js. However, I encountered a warning which didn't allow me to see the updates for that particular vue component. I am quite lost of what else did I miss out. – Nehemiah Chan Dec 15 '19 at 12:49

0 Answers0