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?
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.
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.
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.
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.
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With