简体   繁体   中英

Difference between Svelte REPL and local output

TL;DR: Online REPL (Svelte 1.9.1) works, but local is broken. The question: what am I doing wrong, locally?

The following code works in this REPL :

  {{grades}}<br>
  {{#each guesses as guess, i}}
      {{#each guess as slot}}
        {{slot}}
      {{/each}}
        =
      {{ grades[i] }}
  {{/each}}


<script>
  export default {
    data () {
      return {
        guesses: [
          [0, 1, 1, 3, 6],
        ],
        grades: [
          [1, 2, 2],
        ],
      }
    },
  };
</script>

That is, it produces the output:

1,2,2

01136 = 1,2,2

However, locally (Svelte 1.9.1 on Linux Mint 18.1, 64-bit), that exact same file produces this output:

1,2,2

01136 = undefined

As you can see, it accesses grades just fine, but not grades[i] within the #each loop. The console reports no errors.

One other mysterious thing

If I remove these lines:

      {{#each guess as slot}}
        {{slot}}
      {{/each}}

...then the local rendering becomes:

1,2,2

= 1,2,2

So how does that #each block make grades[i] undefined all of the sudden...but only locally?

Additional environment info

The local version is pulled in via the following:

Game.js

import Game from '../components/Game.html';

const GameComponent = new Game({
  target: document.querySelector('main'),
});

export default GameComponent;

main.js

/* eslint-disable no-unused-vars */

import Game from './js/Game';

index.html

<!doctype html>
<html>
<head>
  <title>CheaterMind</title>
  <link rel="stylesheet" type="text/css" href="colours.css">
</head>
<body>
  <main></main>
  <script src='../dist/main.js' charset='utf-8'></script>
</body>
</html>

The setup is a copy of https://github.com/charpeni/svelte-example and I'm using npm run build:watch .

yarn upgrade svelte 在本地更新为svelte 1.9.1。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM