I roughly followed this article to make a component draggable:
<template>
<div ref="draggableContainer" class="draggable-container">
<div class="draggable-header" @mousedown="dragMouseDown">
<slot name="dragger"></slot>
</div>
<slot></slot>
</div>
</template>
and then in my Calculator.vue
component I have:
<template>
<Draggable class="calculator">
<input type="text" class="calculator-screen" slot="dragger" value="" />
<div class="calculator-keys">
<button type="button" class="operator" value="+">+</button>
<button type="button" class="operator" value="-">-</button>
<button type="button" class="operator" value="*">×</button>
<button type="button" class="operator" value="/">÷</button>
<button type="button" value="7">7</button>
<button type="button" value="8">8</button>
<button type="button" value="9">9</button>
<button type="button" value="4">4</button>
<button type="button" value="5">5</button>
<button type="button" value="6">6</button>
<button type="button" value="1">1</button>
<button type="button" value="2">2</button>
<button type="button" value="3">3</button>
<button type="button" value="0">0</button>
<button type="button" class="decimal" value=".">.</button>
<button type="button" class="all-clear" value="all-clear">AC</button>
<button type="button" class="equal-sign operator" value="=">=</button>
</div>
</Draggable>
</template>
Both components use slot
in different ways, in the draggable-maker
as a tag, and in the calculator as an attribute. However, this is not Vue 3 compatible due to the use of slot
s. Here's the error I'm getting:
Can someone please suggest how I may fix this?
The slot
attribute is deprecated and it's replaced by v-slot:slotname
for named slots and you should use it as follows :
<Draggable class="calculator">
<template v-slot:dragger>
<input type="text" class="calculator-screen" value="" />
<div class="calculator-keys">
<button type="button" class="operator" value="+">+</button>
<button type="button" class="operator" value="-">-</button>
<button type="button" class="operator" value="*">×</button>
<button type="button" class="operator" value="/">÷</button>
<button type="button" value="7">7</button>
<button type="button" value="8">8</button>
<button type="button" value="9">9</button>
<button type="button" value="4">4</button>
<button type="button" value="5">5</button>
<button type="button" value="6">6</button>
<button type="button" value="1">1</button>
<button type="button" value="2">2</button>
<button type="button" value="3">3</button>
<button type="button" value="0">0</button>
<button type="button" class="decimal" value=".">.</button>
<button type="button" class="all-clear" value="all-clear">AC</button>
<button type="button" class="equal-sign operator" value="=">=</button>
</div>
</template>
</Draggable>
don't forget to remove slot="dragger"
from input
element, the syntax that you use is deprecated from the version 2.6.0 which will include the v3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With