编写一个组件页面,在template中有一个按钮,三个输入框,在script中定义一个数组变量其值为[4,5],将数组变量解构赋值给其中两个输入框, 点击按钮,调用箭头函数,将两个输入框中的数字相加,赋给第三个输入框
时间: 2023-05-31 19:05:20 浏览: 54
<template>
<div>
<input v-model="num1" type="number">
<input v-model="num2" type="number">
<input v-model="result" type="number" disabled>
<button @click="add">计算</button>
</div>
</template>
<script>
export default {
data() {
return {
num1: '',
num2: '',
result: '',
arr: [4, 5]
}
},
mounted() {
[this.num1, this.num2] = this.arr
},
methods: {
add: () => {
this.result = Number(this.num1) + Number(this.num2)
}
}
}
</script>
相关问题
编写一个组件页面,在template中有个按钮,三个输入框,在scriot中定义一个数组变量其值为[4,5]
<template>
<div>
<input type="text" v-model="input1">
<input type="text" v-model="input2">
<input type="text" v-model="input3">
<button @click="handleClick">点击</button>
</div>
</template>
<script>
export default {
data() {
return {
arr: [4, 5],
input1: '',
input2: '',
input3: ''
}
},
methods: {
handleClick() {
console.log(this.arr);
}
}
}
</script>
编写一个组件页面,在template中有一个按钮,三个输入框
<template>
<div>
<input type="text" v-model="input1">
<input type="text" v-model="input2">
<input type="text" v-model="input3">
<button @click="clickHandler">提交</button>
</div>
</template>
<script>
export default {
data() {
return {
input1: '',
input2: '',
input3: ''
}
},
methods: {
clickHandler() {
console.log(this.input1, this.input2, this.input3)
}
}
}
</script>
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)