vue3写法
javascript
<template>
<div>
<input placeholder="请输入" style="color: red; font-size: 80px;" v-model="inputValue" />
<button @click="handleSubmit">提交</button>
</div>
</template>
<script setup>
import { ref } from 'vue';
const inputValue = ref('');
function handleSubmit() {
if (inputValue.value === '') {
alert('请输入内容')
} else {
alert('已输入')
}
}
</script>
vue2写法
javascript
<template>
<div>
<input v-model="inputValue" />
<button @click="handleSubmit">提交</button>
</div>
</template>
<script>
export default {
data() {
return {
inputValue: ''
}
},
methods: {
handleSubmit() {
if (this.inputValue === '') {
alert('请输入内容')
} else {
// do something...
}
}
}
}
</script>