Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I get 'avoid using JavaScript unary operator as property name' in vue.js?

In a vue.js template, I have this code to delete a joke

<div  v-on:click="delete(joke)" class="btn btn-sm">delete</div>

and the method to do so:

delete: function(joke) {
    console.log('delete requested');
    axios.post( this.BASE_URL + "/delete" , {
        id: joke.id,
        token: this.token,
    }).then( (res) => { 
        this.$router.push({ path: '/' });
    })
    .catch( (error) => {
        console.log(error);             
  });
},

I get this error:

avoid using JavaScript unary operator as property name: "delete(joke)" in expression v-on:click="delete(joke)"

The odd thing is that, in other components, I pass the same joke object to methods in the same manner and get no errors.

I'm wondering what is wrong here and how to fix it?

like image 401
Karlom Avatar asked Nov 20 '17 15:11

Karlom


People also ask

What is JavaScript unary operator?

A unary operation is an operation with only one operand. This operand comes either before or after the operator. Unary operators are more efficient than standard JavaScript function calls. Additionally, unary operators can not be overridden, therefore their functionality is guaranteed.

Which operator is unary operator?

The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean. The increment/decrement operators can be applied before (prefix) or after (postfix) the operand.

Is negation a unary operation?

The unary negation operator (-) produces the negative of its operand. The operand to the unary negation operator must be an arithmetic type. Integral promotion is performed on integral operands, and the resultant type is the type to which the operand is promoted.

What does unary plus operator do to string representations of integers?

It can convert string representations of integers and floats, as well as the non-string values true , false , and null . Integers in both decimal and hexadecimal ( 0x -prefixed) formats are supported. Negative numbers are supported (though not for hex). Using the operator on BigInt values throws a TypeError.


1 Answers

I'm wondering what is wrong here

delete is an operator defined in JavaScript.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete

and how to fix it?

Choose a different method name than delete ...

like image 62
CBroe Avatar answered Oct 05 '22 22:10

CBroe