我正在使用 Svelte (v2.7) 和 Sapper (v0.12)。根据the docs , this.refs
应该可用,但对我来说它是 undefined
,在 oncreate
和自定义方法中。
我的 index.html 看起来像这样:
<select id="wifi-ssid" ref="wifi-ssid">
...
<script>
export default {
oncreate() {
console.log('this.refs is undefined here', this.refs);
},
methods: {
getIsValid() {
console.log('this.refs is undefined here too', this.refs);
// ...
},
// ...
}
};
</script>
我假设这不是一个错误(否则每个人都会遇到它?)而且我有问题,因为这是我第一次使用它。
最佳答案
这已被弃用,我相信新语法是 <select bind:this={wifissid}>
关于 slim :引用未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50723487/