input-date pour Vue3

Pareil que pour nl2br, j’ai voulu utiliser un champ date dans Vue3 mais le code que j’utilisais dans vue.js ne fonctionne pas.

Voici mon adaptation

// adapted from https://acdcjunior.github.io/how-bind-date-object-to-input-date-vue.js-v-model.html { props: ['modelValue'], emits: ['update:modelValue'], setup() { const dateToYYYYMMDD = (d) => { // alternative implementations in https://stackoverflow.com/q/23593052/1850609 try { return d && new Date(d.getTime()-(d.getTimezoneOffset()*60*1000)).toISOString().split('T')[0]; } catch(e) { return null; } }; return { dateToYYYYMMDD, } }, template: ` <input v-model="value" type="date" @input="$emit('update:modelValue', $event.target.valueAsDate)" /> `, computed: { value: { get() { return this.dateToYYYYMMDD(this.modelValue); }, set(value) { } } } }
Langage du code : JavaScript (javascript)

nl2br pour Vue3

J’ai voulu utiliser nl2br pour vue.js mais il n’est pas compatible avec Vue3.

Voici mon adaptation

// Adapted from https://github.com/inouetakuya/vue-nl2br/ { props: { tag: { type: String, required: true, }, text: { type: String, required: true, }, className: { type: String, required: false, }, }, setup(props) { return () => Vue.h( props.tag, { 'class': props.className }, props.text.split('\n').reduce((accumulator, string) => { if (!Array.isArray(accumulator)) { return [accumulator, Vue.h('br'), string] } return accumulator.concat([Vue.h('br'), string]) }) ); }, };
Langage du code : JavaScript (javascript)