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

148
Views
How to import multiple components to main.js in svelte js?

How could import an svelte component to a "target" different to body?

https://github.com/sveltejs/template/blob/master/src/main.js

I am trying the next:

import App from './App.svelte';
export default new App({ target: document.body.div});

How could I export multiple componentes to different targets?

import App1 from './App1.svelte';
import App2 from './App2.svelte';
export default new App1({ target: document.body.div1});   
export default new App2({ target: document.body.div2});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use named exports, like:

import App1 from './App1.svelte';
import App2 from './App2.svelte';

export const app1 = new App1({ target: document.getElementById("app1")});   
export const app2 = new App2({ target: document.getElementById("app2")});

And in Your html you need to have the following elements:

<div id="app1"></div>
<div id="app2"></div>
about 4 years ago · Juan Pablo Isaza Report

0

You can export a "const" object instead "default" to html element #ids with document.getElementById() or body tag names with document.getElementsByTagName()

import App1 from './App1.svelte';
import App2 from './App2.svelte';

export const app1 = new App1({ target: document.getElementById("div1") });   
export const app2 = new App2({ target: document.getElementById("div2") });
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!