Answer the question
In order to leave comments, you need to log in
Why doesn't VueJS see the component's method?
<ul v-if="identification === 1" id="passport-RF" :identification="1" :last_name="last_name" :first_name="first_name"
:patronymic="patronymic">
<table>
<thead>
<tr>
<td>Паспорт выдан</td>
<td>Дата выдачи</td>
<td>Код подразделения</td>
<td>Серия</td>
<td>Номер</td>
</tr>
</thead>
<tbody>
<tr>
<td><textarea></textarea></td>
<td><input type="date"></td>
<td><input type="number">-<input type="number"></td>
<td><input type="number"></td>
<td><input type="number"></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<td>Фамилия</td>
<td>Имя</td>
<td>Отчество</td>
<td>Пол</td>
<td>Дата рождения</td>
<td>Место рождения</td>
</tr>
</thead>
<tbody>
<tr>
<td><input v-model="last_name" type="text"></td>
<td><input v-model="first_name" type="text"></td>
<td><input v-model="patronymic" type="text"></td>
<td>
<gender :gender="gender"></gender>
</td>
<td><input type="date"></td>
<td><input type="text"></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<td>Регион</td>
<td>Пункт</td>
<td>Район</td>
<td>Улица</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
<td><span @click="addPassportRF()" class="button">Добавить документ</span></td>
</tr>
</tbody>
</table>
</ul>
Vue.component('passport-rf', {
delimiters: ['${', '}'],
data() {
return {
type_identification: null,
patient: null,
passport_issued: null,
date_of_issue: null,
unit_code_1: null,
unit_code_2: null,
series: null,
number: null,
last_name: null,
first_name: null,
patronymic: null,
gender: null,
date_of_birth: null,
place_of_birth: null,
region: null,
location: null,
district: null,
street: null,
}
},
template: '#passport-rf',
mounted: function () {
this.$root.$on('gender', function (gender) {
this.gender = gender
});
this.$root.$on('identification', function (identification) {
this.identification = identification
});
},
methods: {
addPassportRF: function () {
this.$http.post('http://' + window.location.host + '/api/identifications/',
{
message: null,
identification: this.identification,
patient: this.patient,
passport_issued: this.passport_issued,
date_of_issue: this.date_of_issue,
unit_code_1: this.unit_code_1,
unit_code_2: this.unit_code_2,
series: this.series,
number: this.number,
last_name: this.last_name,
first_name: this.first_name,
patronymic: this.patronymic,
gender: this.gender,
date_of_birth: this.date_of_birth,
place_of_birth: this.place_of_birth,
region: this.region,
location: this.location,
district: this.district,
street: this.street,
},
{headers: {'X-CSRFToken': getCookie()}}
).then(response => {
this.message = 'Учетная запись документа создана';
}, response => {
this.message = 'Все поля должны быть заполнены';
});
}
},
})
[Vue warn]: Property or method "addPassportRF" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
(found in <Root>)
warn @ vue.js:597
warnNonPresent @ vue.js:1901
has @ vue.js:1934
click @ VM2411:3
invoker @ vue.js:2029
fn._withTask.fn._withTask @ vue.js:1828
VM2411:3 Uncaught TypeError: addPassportRF is not a function
at click (eval at createFunction (vue.js:10667), <anonymous>:3:2773)
at invoker (vue.js:2029)
at HTMLSpanElement.fn._withTask.fn._withTask (vue.js:1828)
Answer the question
In order to leave comments, you need to log in
Without brackets:
In this case, a reference to a function (method) must be passed to the event handler. Now, if the method returned a function, then it would be possible with brackets.
PS: Decompose the component - don't make them so huge.
PS 2: If your element behaves like a button, then stick to the semantics and use<span @click="addPassportRF()" class="button">
<button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question