1

Using vuejs. Is it possible to change the value some data variable from an external file? For example

file1.js

export default{
   data: function(){
      somevar: false
        }
      }

file2.js

import otherfile from "./file1.js"
otherfile.data().somevar = true

This didn't work. The somevar value wasn't changed in file2.js . How can I change the value in file2.js and if not possible what is the correct way to do this?

2
  • share live demo which not works for you ? Commented Nov 29, 2017 at 13:02
  • You probably needed a prop rather than data. Commented Nov 30, 2017 at 11:06

1 Answer 1

1

it would likely be easier to set up file1.js so that somevar is a computed property that relies on the import of file2.

Using vuejs. Is it possible to change the value some data variable from an external file? For example

file1.js

import importedVar from './file2.js'

export default{
   computed: {
      somevar: function() {
          if (importedVar) {
            return importedVar
          } else {
            return false
          }
        } 
      }

file2.js

export default true
Sign up to request clarification or add additional context in comments.

2 Comments

will somevar change when importedVar is changed?

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.