【发布时间】:2020-08-25 08:42:55
【问题描述】:
大家好,我想在 vue 中重现这样的效果:
正如您所见,当用户开始在输入框中输入时,标签会移动并显示出来。
但是我很难访问输入框中的值以检查它们是否为空。
这是我的 vue 模板:
<template>
<div class="desktop-landing-search">
<!---------------------------------------JOB SEARCH WRAPPER--------------------------------------->
<div class="desktop-landing-search__search-wrapper">
<div class="desktop-landing-search__input-box">
<label for="inputType" ref="typeLabel">Graduate or Internship</label>
<input
type="text"
class="desktop-landing-search__input-box__input-search"
id="inputType"
placeholder="Graduate or Internship"
ref="inputJobType"
v-on:input="showLabel('type')"
/>
</div>
<div class="desktop-landing-search__input-box">
<label for="inputIndustry" ref="industryLabel">Industry</label>
<input
type="text"
class="desktop-landing-search__input-box__input-search"
id="inputIndustry"
placeholder="Industry"
ref="inputIndustry"
/>
</div>
<div class="desktop-landing-search__input-box">
<label for="inputLocation" ref="locationLabel">Location</label>
<input
type="text"
class="desktop-landing-search__input-box__input-search"
id="inputLocation"
placeholder="Location"
ref="inputLocation"
/>
</div>
<div class="desktop-landing-search__input-box">
<button class="desktop-landing-search__btn-search">Search</button>
</div>
</div>
</template>
这是我用来显示标签的方法:
<script>
export default {
name: "DesktopLandingSearch",
methods: {
showLabel: function(input) {
if (this.input === "type" && this.refs.inputJobType.value != "") {
this.refs.typeLabel.classList.toggle("show-label");
window.alert("testing job type");
}
if (this.input === "industry" && this.refs.inputIndustry.value != "") {
this.refs.industryLabel.classList.toggle("show-label");
window.alert("test job industry");
}
if (this.input === "location" && this.refs.inputLocation.value != "") {
this.refs.locationLabel.classList.toggle("show-label");
window.alert("test job location");
}
}
}
};
</script>
这是我要切换的类:
.show-label {
top: -130%;
opacity: 1;
}
谁能告诉我我做错了什么?
【问题讨论】:
标签: javascript html css vue.js sass