I've got a vue web component with a numeric prop on it, and through some testing have found that doing something like this doesn't work in setting the prop value...
<script src="https://unpkg.com/vue@2"></script>
<script src="./mycomponents.js"></script>
<my-component myProp="40"></my-component>
But this will...
<script src="https://unpkg.com/vue@2"></script>
<script src="./mycomponents.js"></script>
<my-component id="mycmp"></my-component>
<script type="module">
const myComponent = document.getElementById("mycmp");
myComponent.myProp = 40;
</script>
Example component code:
<template>
<p>{{myProp}}</p>
</template>
<script>
export default {
name: 'MyComponent',
props: {
myProp: {
type: Number,
default: 0
}
}
}
</script>
I'm guessing maybe this is a timing thing, like when doing it through the html attributes the component hasn't finished being properly initialised yet? Though all the examples I saw of other people using vue web-components seemed to suggest that this should be a pretty basic use case. Hopefully it's just me doing something dumb.
Any help greatly appreciated!
type: [String, Number]and then everywhere you access the prop - you should coerce it to Number.my-prop="40"instead ofmyProp="40". It might behave the same asdata-*attributes, which are expected to bedata-my-attrin HTML, but are accessed viaelm.dataset.myAttrin JavaScript.