1

Following the official guide, I am trying to build a simple form that outputs its input into a div on the same template.

Here is my code

<template lang="html">
  <div>
    <input type="text" name="firstname" value="" v-model="firstname">
    <input type="submit">

    <div>
      <h1>First name</h1>
      <p>{{ firstname }}</p>
    </div>

  </div>
</template>

<script>
  export default {
    data: function() {
      'firstname': '',
    }
  }
</script>

<style>
</style>

And here is the error:

SyntaxError: Unexpected token, expected ; (28:15)

  26 | export default {
  27 |   data: function() {
> 28 |     'firstname': '',
     |                ^    


 @ ./src/App.vue 8:18-97

I have tried to

  • remove the quotes from the data keys
  • change the data function to an object

Frankly out of ideas as this is so close to the documentation.

Any ideas?

2 Answers 2

2

You have a syntax error as you're not actually returning an object in the function:

data: function() {
  return {
    firstname: '',
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

data must be a function which must return the object of defined data variables, like following:

  data: function () {
    return {
      'firstname': '',
    }
  }

1 Comment

Yeah that was overlooked

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.