0

I have a json look like below and I wish to import from different component, because this json contain require and Math etc. Unable to save into json file format

let test = [
    {
      name:"A",
      imgSrc: require('@/assets/img/A.png'),
      range: Math.pow(10, 6),
      isShow: true
    },
    {
      name:"B",
      imgSrc: require('@/assets/img/B.png'),
      range: Math.pow(10, 2),
      isShow: false
    }
  ];
1
  • 1
    make this as a .js file then try to import Commented Dec 14, 2021 at 5:17

1 Answer 1

1

Copy that declaration into a JavaScript file, and use the export keyword in front of it:

// products.js
export let test = [/*...*/]
 👆

Then in another JavaScript file, you could use the import keyword to pull in the variable by name:

// main.js
import { test } from './products'
  👆
Sign up to request clarification or add additional context in comments.

Comments

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.