Skip to content

Split JS code from HTML #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
angjelkom opened this issue Dec 5, 2016 · 7 comments
Closed

Split JS code from HTML #127

angjelkom opened this issue Dec 5, 2016 · 7 comments

Comments

@angjelkom
Copy link

angjelkom commented Dec 5, 2016

Just a question. As the title says how can I split the js code from the html file? so:

`
Click Me

<script> export default { data () { return { email: '', password: '' } } methods: { login () { console.log(email, password); } } }; </script>`

How can I have the js code in a seperate js file?

@AgentEpsilon
Copy link

Put the code in a .js file (say login.js), then replace your script tag with <script src="login.js"></script>.

@angjelkom
Copy link
Author

@AgentEpsilon isn't there a way like putting both: Login.html and Login.js in same path and let Svelte handle?

@AgentEpsilon
Copy link

I'd look in to setting up some sort of bundler such as Webpack, Browserify, or Rollup.

@rhengles
Copy link

rhengles commented Dec 5, 2016

See #65

@Rich-Harris
Copy link
Member

Will close this as it's a dupe of #65 – this isn't currently supported.

@EchoNox when you're including code samples in comments, there's a way to render them as code blocks – use ``` (three backticks) optionally followed by a language id like js or `html`:

screen shot 2016-12-06 at 10 20 39 am

<input type='email' bind:value='email' /> <input type='password' bind:value='password' />
<button on:click='login()'>Click Me</button>

<script>
export default {
    data () {
      return {
        email: '', password: ''
      }
    }
    methods: {
      login () {
        console.log(email, password);
      }
    }
  };
</script>

@angjelkom
Copy link
Author

@Rich-Harris ok thanks I used the code button but it didn't transform sorry

@Rich-Harris
Copy link
Member

Yep, the code button is for inline code, not for blocks of code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants