当前位置:网站首页>表单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)
- (3) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Node_explorer+Jmeter)
- 吃瓜教程task04 第5章 神经网络
- EOF, feof function, ferror function in C language
- 【翻译】博客游戏项目Q1K3 – 制作
- Redis - the solution to the failure of connecting to the redis server in linux using jedis
- C - file operations fseek () function, ftell, rewind, rounding
- 【C语言进阶】第一篇深度剖析整数数据在内存中的存储(一)
- C语言结构体详解 (2) 结构体内存对齐,默认对齐数
- 博客帮助文档
猜你喜欢
随机推荐
C语言——函数的使用
Randomly generate uuid using rand function
C语言结构体详解 (2) 结构体内存对齐,默认对齐数
【背包】采药题解
QT Mat转HObject和HObject转Mat 图像视觉处理
数组的用法
怎么用管理员方式打开压缩包
【记录】没用知识点 - 智力题
[转载]Verilog testbench总结
win下Anaconda(环境配置等)和pycharm安装详细教程
Flask框架学习:模板渲染与Get,Post请求
ClionIDE通过指定编译器编译
程序员小白的自我救赎之路。
【转载】如何理解数据集中【训练集】、【验证集】和【测试集】
一、Jmeter环境部署
Flask framework to study: the debug and configuration items
CSDN 社区内容创作规范
Visual Studio上一些Error的解决方案
win下clion打包的.exe文件在无运行环境的电脑运行显示缺失各种.dll
全国青少年信息学奥林匹克联赛大纲