在我的应用程序中,用户在输入字段内提供样式代码。我想添加弹出确认模式,其中包含包含提供的样式代码数量的消息。我有以下内容:
<template>
<h4>Style number</h4>
<FormulateForm v-model="styleCodes">
<FormulateInput
name="product_codes"
placeholder="Style number"
/>
<button
type="button"
class="btn btn-primary"
@click="syncProducts"
>
Sync
</button>
</FormulateForm>
</template>
<script>
export default {
name: 'SyncProducts',
data() {
return {
styleCodes: [],
}
},
computed: {
productsToSyncAmount () {
return this.styleCodes.length
},
methods: {
async syncProducts() {
let confirmationText = `Do you want to ${this.productsToSyncAmount} sync products?`
if (this.productsToSyncAmount === 0) {
ModalController.showToast('', 'Type product codes for sync first, please!', 'warning')
}
else if (await ModalController.showConfirmation('Confirmation', confirmationText)) {
try {
ModalController.showLoader()
await createApparelMagicProductsRequest(this, this.styleCodes)
} catch (data) {
const errorMessage = `Error occurred during queueing products to sync - `
ModalController.showToast('', errorMessage + data?.message, 'error')
} finally {
this.styleCodes = []
}
}
},
}
}
</script>
我认为关键的部分是这个
methods: {
async syncProducts() {
let confirmationText = `Do you want to ${this.productsToSyncAmount} sync products?`
我不明白为什么这段代码会根据长度生成未定义的数字并向我显示消息 Do you want to undefined sync products?。在控制台内我有:
[Vue warn]:无效的道具:道具“formulateValue”的类型检查失败。期望的对象,得到数组
如何解决这个问题?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我认为问题在于您向
FormulateForm提供了一个数组。 根据文档,它需要一个对象。https://vueformulate.com/guide/forms/#setting-initial -值