Skip to content

Make external function or data accessibles inside the vue methods #91

@eliottparis

Description

@eliottparis

Hi, first of all, thanks for this library !

I'm trying to figure out the way you can pass external functions or data into the vue script.

Why in the following code the toto value is accessible in the data function but not in the trigger method ?

 [...]
<script>

let toto = 42;
let bar = function() {
    console.log("bar function called");
}

export default {
    data() {
      return {
        val: toto // (42)
      }
    },
    methods: {
      trigger() {
        bar(); // (Uncaught ReferenceError: bar is not defined)
        console.log(toto); // (Uncaught ReferenceError: toto is not defined)
      }
    }
}
</script>
 [...]

PS: I'm a javascript newbie, so sorry if the answer is obvious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions