当前位置:网站首页>表单input控件数据双向绑定
表单input控件数据双向绑定
2022-08-11 05:17:00 【-加油】
1、react
import React from "react"
//类组件
class Count extends React.Component {
state = {
message: 'this'
}
inputChange = (e) => {
console.log(e.target.value)
console.log('input')
this.setState({
message: e.target.value
})
}
render () {
return (
<>
<input type="text"
value={
this.state.message}
onChange={
this.inputChange} />
<p>实现了双向数据绑定:{
this.state.message}</p>
</>
)
}
}
function App () {
return (
<div className="App">
<Count></Count>
</div>
)
}
export default App
2、vue
<template>
<div id="app">
<input type="text" @input="inputChange" :value="message" />
<p>双向数据绑定:{
{
message}}</p>
<p>'v-model ' = ':value' + '@input' 实现的:</p>
<input type="text" v-model="message" />
</div>
</template>
<script>
export default {
data() {
return {
message:'this'
}
},
methods:{
inputChange(e){
console.log(e.target.value);
console.log('input');
this.message = e.target.value;
}
}
}
</script>
<style>
</style>
边栏推荐
- The most complete installation tutorial of Pytorch (one step)
- [C language from elementary to advanced] Part 2 Initial C language (2)
- C语言——函数的使用
- 第4章 复合类型-1
- 搭建PX4开发环境
- 第13章 类的继承-1
- 吃瓜教程task01 第1章 绪论
- 吃瓜教程task03 第4章 决策树
- Redis - the solution to the failure of connecting to the redis server in linux using jedis
- 07-JS事件:事件类型、事件对象、事件传播、事件委托
猜你喜欢
随机推荐
c指针学习(2)
C语言——动态内存分配常见的错误案例
性能效率测试
在项目中使用flex布局的justify-content:space-around;遇到的问题,(数量为单数)
task04 Pytorch进阶训练技巧
ClionIDE通过指定编译器编译
LeetCode43. String multiplication (this method can be used to multiply large numbers)
【C语言从初阶到进阶】第二篇 初始C语言(二)
软件测试风险识别
简单做份西红柿炒蛋778
04-开发自己的npm包及发布流程详细讲解
C语言——函数的使用
Flask框架学习:模板渲染与Get,Post请求
(1) Construction of a real-time performance monitoring platform (Grafana+Influxdb+Jmeter)
C语言之EOF、feof函数、ferror函数
手推卷积神经网络参数(卷积核)求导
设计三级联动
QT circle函数(图片标注)
第4章 复合类型-1
08-Express路由详解