I am confident in my code, but why is eslint throwing an error? How can this be happening?

I have been diving into Vue render functions, and here is my index.js:

<script>
export default {
  name:'MyHead',
  props:{
      level:Number
  },
  render(h){
    return h('div', [h('h'+this.level,'this is head' + this.level)])
  }
}
</script>

While working in vscode, I encountered some errors:

https://i.sstatic.net/SG7pi.png

To resolve the errors, I disabled javascript.validate.enable in settings.json, which made them disappear.

However, when running npm run lint to lint the code, a new error emerged:

error: Parsing error: Unexpected token, expected "}"

https://i.sstatic.net/92vgb.png

I wonder what caused this? Could it be due to my eslint configuration not being correct? Thank you for your assistance.

Here are my devDependencies:

{
    "@vue/cli-plugin-babel": "^3.4.0",
    "@vue/cli-plugin-eslint": "^3.4.0",
    "@vue/cli-service": "^3.4.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^7.6.0",
    "eslint-plugin-vue": "^6.2.2",
    "less": "^3.9.0",
    "less-loader": "^5.0.0",
    "mockjs": "1.0.1-beta3",
    "vue-template-compiler": "^2.5.21"
  }

My .eslintrc.js file looks like this:

module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true
  },
  extends: [
    'eslint:recommended',
    'plugin:vue/essential'
  ],
  plugins: [
    'vue'
  ],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  // NOTE 异步加载路由报错:Parsing error: Unexpected token import
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: '2018',
    sourceType: 'module'
  },
  rules: {
    quotes: [2, 'single', { 'allowTemplateLiterals': true }],
    semi: [2, 'never'],
    // More rules go here...
  }
}

Answer №1

When creating a component in a JS file using the render function, there is no need to include a script tag.

export default {
  name:'MyHead',
  props:{
      level:Number
  },
  render(h){
    return h('div',[h('h'+this.level,'This is header' + this.level)])
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The function was called indirectly and the member appeared to be undefined

class Greetings{ constructor(user) { this.user = user; this.function_map = {"welcomeUser" : this.welcomeUser}; } welcomeUser(){ console.log(this.user); } } let g = new Greetings("Alice"); g.welcomeUser(); //=> o ...

Integrate geographic data in GeoJSON format into a Leaflet map by using the Django template

In my Django view, I am fetching results of an SQL query and rendering it on the index.html page of my web map. The POST request successfully returns the acreage calculated from the SQL query to the page. I am also attempting to display the geojson data fr ...

Examples of Javascript closures in action with a for loop

I decided to stop my research here. Below is the question I have: After reading this post, I grasped the concept illustrated by the code snippet provided. var funcs = {}; for (var i = 0; i < 3; i++) { // creating 3 functions funcs[i] = functi ...

How can eval() be effectively replaced in JavaScript?

Having trouble with javascript eval()? I've encountered bugs and decided to replace all instances of it. Here's an example of what I've changed: var abc = "item." + str3 + ".power"; abc = eval(abc); Now, it's been updated to: var abc ...

Steps for generating instances of an HTML page and dynamically adding them to a list on the main page

I have a main HTML page and I need to insert a dynamically generated list from a template in another HTML file that I created. The template for each item in the list is located on a separate HTML page. My goal is to create multiple instances of this HTML ...

"Reacting to click events, all buttons have been successfully updated in ReactJS

When a button is clicked, all buttons are updated simultaneously. However, I am looking to only change the state of the specific button that is clicked. Please refer to the image links and code provided below. import React from 'react'; import & ...

Filtering Events using Radio Buttons in FullCalendar via JQuery

Currently, I am attempting to utilize a set of buttons in the JQUERY FullCalendar to filter events. My implementation successfully filters events based on the 'dog' or 'cat' category using a dropdown. However, I am struggling to achiev ...

Ways to require semicolons in a Typescript interface

When declaring a TypeScript interface, both , (comma) and ; (semicolon) are considered valid syntax. For example, the following declarations are all valid: export interface IUser { name: string; email: string; id: number; } export interface IUser { ...

Only allowing designated email addresses to authenticate using Gmail Oauth

Is there a way I can limit logins by doing the following? I'm facing an issue where the page keeps reloading constantly after logging in once. function onSignIn(googleUser) { var profile = googleUser.getBasicProfile(); console.log('Name: ...

Use JavaScript to change the CSS pseudo-class from :hover to :active for touch devices

Looking to eliminate hover effects on touch devices? While it's recommended to use a hover class for hover effects, instead of the hover pseudo-class, for easier removal later on, it can be a challenge if your site is already coded. However, there&apo ...

Generate a div element through a looping mechanism

I added a new div with the following CSS code: <div id="r1" class="ansbox"></div> <div id="r2" class="ansbox"></div> <div id="r3" class="ansbox"></div> <div id="r4" class="ansbox"></div> <div id="r5" clas ...

What are the appropriate situations to utilize Q.defer versus using Promise.resolve/reject?

I've been working with nodejs and I'm curious about when to use Q defer over Promise.resolve/reject? There are numerous examples of both methods, such as: // using Q defer function oneWay(myVal) { var deferred = Q.defer(); if (myVal < 0) ...

How can I create automated tests for a Vue.js Tailwind CSS application using Cypress?

As I review the Cypress.io docs, I notice that the examples on how to write tests heavily rely on class selectors. However, my TailwindCSS application consists of numerous small classes rather than the specific ones mentioned in the examples, making it cha ...

What is the process for setting environment variables in a Svelte project?

I'm brand new to working with Svelte and I want to incorporate environment variables like base_url into different components. I've read that I can set up a store to hold these values, for example: const DataStore = writable([ { base_url: & ...

Incorporate chat functionality into Angular using an embedded script

Recently, I encountered an issue with inserting an online chat using a Javascript script into my website. My initial plan was to add it directly to my app.component.html, but unfortunately, it didn't display as expected. I'm now exploring option ...

Eliminate an item from an array of objects utilizing a specific key

Here is the JSON data provided: var data= { 'A' : { 'Total' : 123, 'Cricket' : 76, 'Football' : 12, 'Hockey' : 1, 'None' : 10 }, 'B&ap ...

Determine the total count of files in queue with Uploadify prior to initiating the upload process

When I specify auto: false in the uploadify settings, the upload process will only start when the submit button is clicked. Once the onQueueComplete event is triggered, the form will be submitted. However, if no files are selected, the onQueueComplete even ...

Is there a way to delete a field from a JSON object using JavaScript?

Searching for a way in Node.js to eliminate the date and operation fields from the database. Any suggestions on how to do this? Currently, all fields are being transferred to the FE. The collection pertains to MongoDB. collection.find({'recordType&ap ...

The JSONLoader in THREE.js appears to be loading models with only half of their textures

Recently I created a house model in blender and exported it to three.js json format as a single object. However, upon adding it to the scene, only half of the textures showed up while the other half appeared as grey meshes. If you want to see the JSON fil ...

What is causing the list-sorter to malfunction?

This website crashes when executed: <head> <script> var numbersList = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]; var orderedList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ...