Sign in

In Vue single page application, different components import the same JS module, and the data sharing of JS module?

hqtfe edited in Wed, 28 Sep 2022

When I was developing Vue single page application, I found several problems and asked for advice?

  • In a single page application, different . Some common JS modules are often used in Vue components. Do you want to reload each reference? Or will it only be loaded for the first time, and the subsequent references will only be loaded for the first time?
import module1 from './utils/common.js'
  • Why are variables defined in the JS module shared by all components that reference the JS module? In this way, the development of the design will be very confusing, because component a changes the variables of module a, and component B obtains the variables of module a, which is the modified value of component A
1 Replies
commented on Wed, 28 Sep 2022

You can treat the exported variable as a const defined variable