Vue.js实现事件类型转换:地点/作品/人际关系
<template>
<div>
<label>地点:</label>
<input type='text' v-model='location'>
<br>
<label>作品:</label>
<input type='text' v-model='work'>
<br>
<label>人际关系:</label>
<input type='text' v-model='relationship'>
<br>
<button @click='convertToEventType'>转换为事件类型</button>
<br>
<p>新事件类型:{{ new_event_type }}</p>
</div>
</template>
<script>
export default {
data() {
return {
location: '',
work: '',
relationship: '',
new_event_type: ''
}
},
methods: {
convertToEventType() {
let locationValue = this.location.trim() !== '' ? 0 : -1;
let workValue = this.work.trim() !== '' ? 1 : -1;
let relationshipValue = this.relationship.trim() !== '' ? 2 : -1;
if (locationValue === -1 && workValue === -1 && relationshipValue === -1) {
this.new_event_type = '无法确定事件类型';
} else {
let eventType = '';
eventType += locationValue !== -1 ? locationValue : '';
eventType += workValue !== -1 ? workValue : '';
eventType += relationshipValue !== -1 ? relationshipValue : '';
this.new_event_type = eventType;
}
}
}
}
</script>
原文地址: https://www.cveoy.top/t/topic/jk2w 著作权归作者所有。请勿转载和采集!