Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
How do I access data from a js file?

Test.vue

<template>
      <div>
        <button @click="test()">test</button>
      </div>
    </template>
    <script>
    import logs from './data.js'
    export default {
        data () {
            return {
            logitems1: logs.data.infomation,
            logitems2:
          {
            log1d: 1,
            logDetail: "This is some log detail for log 1",
            logType: "general",
            createdBy: "name",
            CreatedAt: "date",
          },
        }
        },
        methods:{
          test(){
             console.log(this.logitems1.log1d)
             console.log(this.logitems2.log1d)
          }
        }
    }
    </script>

data.js

export default {
  data() {
    return {
      infomation: {
        log1d: 1,
        logDetail: "This is some log detail for log 1",
        logType: "general",
        createdBy: "name",
        CreatedAt: "date",
      },
    };
  },
};

Access to logitems2 is possible but I can't access the data in logitems1, which has all the same information. I'm trying to access data from files other than components, which I can't figure out how to access.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to make a functional call.

<script>
    import logs from './data.js'
    export default {
        data () {
            return {
            logitems1: logs.data().infomation,
            logitems2:
          {
            log1d: 1,
            logDetail: "This is some log detail for log 1",
            logType: "general",
            createdBy: "name",
            CreatedAt: "date",
          },
        }
        },
        methods:{
          test(){
             console.log(this.logitems1.log1d)
             console.log(this.logitems2.log1d)
          }
        }
    }
    </script>

But if you just only want the data to be available exporting the object from js file without function would be better approach.

logdata.js

export default logInformation{
    log1d: 1,
    logDetail: "This is some log detail for log 1",
    logType: "general",
    createdBy: "name",
    CreatedAt: "date",
}

and then directly use as

import logInformation from "logdata.js"

console.log(logInformation)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!