VUE - "disabled"在选择字段上不起作用的道具绑定



我正在尝试进行下拉"选择";在我的应用程序中,字段在特定条件下被禁用。

我已经成功地使用了一个道具(disableBtn(来实现了这一点,我从应用程序的根目录传递到了我制作的按钮组件。

我试图在一个选择组件上做同样的事情,但它拒绝将prop(disableOption(传递回子组件,即使它传递回了许多其他绑定的prop,这些prop运行良好,并在下拉列表中正确构建了选项。

我现在正在屏幕上记录这些值,可以看到它们正在主应用程序组件中更新,但由于某种原因,它没有将其传递回孩子。

我在哪里?我的理解是,将要在data((中更改的值存储在app.vue中,然后在子组件中为它们创建一个道具,并将它们绑定到HTML中。这在我的所有其他用例中都运行良好。

app.vue

<template>

<div class="container">
<img alt="logo" src="./assets/logo.png">
<Header title="Provider Manager" :custTZ="custTZ" :shippingState="shippingState" :patientID="patientID" :custName="custFullName" :custEmail="custEmail" :custPhone="custPhone" />

<div v-if="providerVisibility" class="providerInfo">

<Button @btn-click="providerPicked" id="first-avail" text="First Available"  />
<br />
<Select @dd-select="providerPickedSelect" :disabled="disableOption" :selectName="selectName" :id="id" :eligibleProviders="eligibleProviders" :labelFor="labelFor" :labelText="labelText"  />
{{ disableOption }}
</div>
<div v-if="providerSelected" >
<hr>
<br />
<h2>Provider: {{ chosenProvider }} </h2>
<br />
</div>
<div v-if="providerSelected" >
<BookingSlots @selectSlot="removeUnselected" :slots="slots" />
<br />
<Button @btn-click="bookMeeting" text="Confirm Request" />
</div>
</div>  

</template>

<script>
import { ZOHO } from "./assets/ZohoEmbededAppSDK.min.js";
import Header from './components/Header'
import Button from './components/Button'
import BookingSlots from './components/BookingSlots'
import Select from './components/Select'
const axios = require('axios');
export default {
name: 'App',
components: {
Header,
Button,
BookingSlots,
Select
},
data() {
return{
slots: [],
providerVisibility: true,
providerSelected: false,
currentProvider: 'None Assigned',
chosenProvider: '',
custFullName: '',
custEmail: '',
custPhone: '',
shippingState: '',
patientID: '',
custTZ: '',
providerZID: '',
eligibleProviders: [],
disableBtn: false,
disableOption: true,

}
},
methods: {
removeUnselected(id) {
console.log('id', id)
this.slots = this.slots.filter((slot) => slot.id === id)
},
providerPicked(id) {
console.log("id" + id)
console.log("currentProvider",this.currentProvider)
//Toggle front end visibility
this.providerSelected = true;
this.providerVisibility = false;

if(id === "first-avail"){
// hit booking engine, get name of first available
console.log("FIRST AVAIL")
this.chosenProvider = "Need to Hit Booking App";
}
if(id === "current-provider"){
// hit zoho values and get contact assigned provider
console.log("CURRENT PROVIDER")
this.chosenProvider = this.currentProvider;

}

},
providerPickedSelect(id, selectValue) {
if(this.id === "provider-select"){
// Get values from our DB for the provider selected
console.log("Provider-Select")
this.providerSelected = true;
this.providerVisibility = false;
this.chosenProvider = selectValue;
}
},
bookMeeting() {
//Book the meeting
console.log("book meeting called")
}
},
created() {

//Hit zoho and get customer info back
ZOHO.embeddedApp.on("PageLoad",(data) =>
{
console.log(data);
//Custom Business logic goes here
let entity = data.Entity;
let recordID = data.EntityId[0];
ZOHO.CRM.API.getRecord({Entity:entity,RecordID:recordID})
.then((data) => {
console.log(data.data[0])

// Set values scraped from CRM Contact profile
if(data.data[0].provider !== null && data.data[0].provider !== "None Assigned"  ){
this.currentProvider = data.data[0].provider.name;
this.providerZID = data.data[0].provider.id;
}else{
//need to disable button if no doc assigned
this.disableBtn = true;
}


this.custEmail = data.data[0].Email;
this.custFullName = data.data[0].Full_Name;
this.custPhone = data.data[0].Phone;
this.patientID = data.data[0].Patient_ID;
this.shippingState = data.data[0].Mailing_State;
this.custTZ = data.data[0].GTM;

// getEligibleProviders(this.shippingState);

var data = JSON.stringify({
"state":this.shippingState,
});


axios(config)
.then((res) => {
console.log(res.data)
//this.eligibleProviders = res.data;
if(this.eligibleProviders && !this.eligibleProviders.length){
console.log("empty array")
this.eligibleProviders = [{
first_name: "None Avilable in Svc. State", 
last_name: ""
}
];
this.disableOption = true;
}else{
console.log("full array")

}
console.log(this.eligibleProviders)
})
.catch((e) => {
console.log(e);
});

});
});

ZOHO.embeddedApp.init();

this.slots = [
{
id: 1,
text: 'Time Slot 1',
providerFname: 'James',
providerLname: "Appleton"
},
{
id: 2,
text: 'Time Slot 2',
providerFname: 'James',
providerLname: "Johnson"
}
];
this.selectName = "provider-select";
this.id = "provider-select";
this.labelFor = "provider-select";
this.labelText = "Choose a Provider: ";

}

}
</script>

选择.vue

<template>

<br />
<label :for="labelFor">{{ labelText }} {{ disableOption }}</label>

<select  v-on:change="onSelect($event, id)" class="select" :name="selectName" :id="id" :disabled="disableOption" >

<option :value="'none'" selected disabled hidden >Select One</option>
<option :key="provider.id" v-for="provider in eligibleProviders" :value="provider.first_name + ' ' +  provider.last_name" >{{ provider.first_name +" "+ provider.last_name }}</option>

</select>
<br /><br />
</template>

<script>
export default {
name: 'Select',
props: {
selectValue: String,
selectName: String,
id: String,
labelFor: String,
labelText: String,
eligibleProviders: Array,
disableOption: Boolean,
},
methods: {
onSelect($event, id) {
console.log($event.target.value)
this.$emit('dd-select', id, $event.target.value);
}
},
emits: ['dd-select']
}

</script>

按钮.vue

<template>
<button @click="onClick(id)" class="btn" :id="id" :disabled="disableBtn" >{{ text }}</button>
</template>

<script>
export default {
name: 'Button',
props: {
text: String,
id: String,
disableBtn: Boolean,
},
methods: {
onClick(id) {
this.$emit('btn-click', id);

}
}
}

</script>

select.vue中,道具说它想要"disableOption";,但你正在通过disabled="disableOption"

因此您可以尝试使用更新app.vue

<Select
@dd-select="providerPickedSelect"
:disable-option="disableOption"
:select-name="selectName"
:id="id"
:eligible-providers="eligibleProviders"
:label-for="labelFor"
:label-text="labelText"
/>

最新更新