Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svelte: refs undefined

Tags:

svelte

I'm using Svelte (v2.7) and Sapper (v0.12). According to the docs, this.refs should be available, but it's undefined for me, both in oncreate and custom methods.

My index.html looks like this:

<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>

(Full code here).

I'm presuming this isn't a bug (otherwise everyone would have run into it?) and I've got something wrong as it's my first time using it.

like image 963
poshaughnessy Avatar asked Jun 07 '26 17:06

poshaughnessy


1 Answers

This is deprecated, I believe the new syntax is <select bind:this={wifissid}>

like image 147
GrepThis Avatar answered Jun 10 '26 09:06

GrepThis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!