{"id":45119,"date":"2025-04-11T17:23:05","date_gmt":"2025-04-11T09:23:05","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=45119"},"modified":"2025-04-11T17:23:05","modified_gmt":"2025-04-11T09:23:05","slug":"%e6%80%8e%e4%b9%88%e7%94%a8react%e5%81%9a%e4%b8%80%e4%b8%aa%e7%a7%bb%e5%8a%a8app","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2025\/45119\/","title":{"rendered":"\u600e\u4e48\u7528react\u505a\u4e00\u4e2a\u79fb\u52a8app?"},"content":{"rendered":"<p>React\u662fFacebook\u5f00\u53d1\u7684\u4e00\u79cdJavaScript\u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa\u7528\u6237\u754c\u9762\u3002\u5b83\u53ef\u4ee5\u8f7b\u677e\u5730\u6784\u5efa\u4ea4\u4e92\u5f0f\u7528\u6237\u754c\u9762\uff0c\u4f7f\u5f97\u6211\u4eec\u5f00\u53d1Web\u5e94\u7528\u66f4\u52a0\u9ad8\u6548\u53ef\u7ef4\u62a4\u3002\u5728\u8fd9\u91cc\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528React\u6765\u5f00\u53d1\u4e00\u4e2a\u79fb\u52a8\u5e94\u7528\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5React Native\uff0c\u5b83\u662f\u4e00\u4e2a\u57fa\u4e8eReact\u6846\u67b6\u7684\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u5de5\u5177\u3002React Native\u4f7f\u7528JavaScript\u8bed\u8a00\u8fdb\u884c\u5f00\u53d1\uff0c\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u4ee3\u7801\u5e93\u6765\u5f00\u53d1iOS\u548cAndroid\u5e94\u7528\u3002\u5b89\u88c5React Native\u7684\u6b65\u9aa4\u53ef\u4ee5\u5728\u5176\u5b98\u7f51\u4e0a\u627e\u5230\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u65b0\u5de5\u7a0b\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>react-native init MyApp<\/p>\n<p>&#8220;`<\/p>\n<p>\u63a5\u7740\u8fdb\u5165\u5230MyApp\u76ee\u5f55\u4e2d\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>cd MyApp<\/p>\n<p>react-native run-ios\/run-android<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u521b\u5efa\u5e76\u542f\u52a8\u65b0\u7684React Native\u9879\u76ee\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u8fdb\u5165\u5230\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\uff0c\u66ff\u6362index.js\u6587\u4ef6\u7684\u5185\u5bb9\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>import React, { Component } from &#8216;react&#8217;;<\/p>\n<p>import { StyleSheet, Text, View } from &#8216;react-native&#8217;;<\/p>\n<p>export default class App extends Component {<\/p>\n<p>  render() {<\/p>\n<p>    return (<\/p>\n<p>\n<p>        Hello, World!<\/p>\n<\/p>\n<p>    );<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>const styles = StyleSheet.create({<\/p>\n<p>  container: {<\/p>\n<p>    flex: 1,<\/p>\n<p>    justifyContent: &#8216;center&#8217;,<\/p>\n<p>    alignItems: &#8216;center&#8217;,<\/p>\n<p>    backgroundColor: &#8216;#F5FCFF&#8217;,<\/p>\n<p>  },<\/p>\n<p>  text: {<\/p>\n<p>    fontSize: 20,<\/p>\n<p>    textAlign: &#8216;center&#8217;,<\/p>\n<p>    margin: 10,<\/p>\n<p>  },<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u540e\uff0c\u5c4f\u5e55\u4e0a\u5c06\u663e\u793a\u4e00\u4e2a\u201cHello, World\u201d\u6587\u672c\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u5c06\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4e00\u4e9b\u66f4\u591a\u7684\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528React Native\u63d0\u4f9b\u7684\u8bb8\u591a\u7ec4\u4ef6\u6765\u5e2e\u52a9\u6211\u4eec\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u201cTextInput\u201d\u7ec4\u4ef6\u7528\u4e8e\u8f93\u5165\u6587\u672c\uff0c\u201cButton\u201d\u7ec4\u4ef6\u7528\u4e8e\u6dfb\u52a0\u6309\u94ae\u7b49\u7b49\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u9879\u76ee\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u4e00\u4e9bReact Native\u7ec4\u4ef6\u7684\u4f7f\u7528\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>import React, { Component } from &#8216;react&#8217;;<\/p>\n<p>import { StyleSheet, View, TextInput, Button, Alert } from &#8216;react-native&#8217;;<\/p>\n<p>export default class App extends Component {<\/p>\n<p>  constructor(props) {<\/p>\n<p>    super(props);<\/p>\n<p>    this.state = {<\/p>\n<p>      inputText: &#8221;,<\/p>\n<p>      allItems: []<\/p>\n<p>    };<\/p>\n<p>  }<\/p>\n<p>  addItem = () =&gt; {<\/p>\n<p>    const { inputText, allItems } = this.state;<\/p>\n<p>    if (inputText !== &#8221;) {<\/p>\n<p>      this.setState({<\/p>\n<p>        allItems: [&#8230;allItems, inputText],<\/p>\n<p>        inputText: &#8221;<\/p>\n<p>      });<\/p>\n<p>    } else {<\/p>\n<p>      Alert.alert(&#8216;Error&#8217;, &#8216;Please enter item name&#8217;, [{ text: &#8216;OK&#8217; }]);<\/p>\n<p>    }<\/p>\n<p>  }<\/p>\n<p>  render() {<\/p>\n<p>    const { inputText, allItems } = this.state;<\/p>\n<p>    const items = allItems.map((item, index) =&gt; {<\/p>\n<p>      r<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-04\/07\/10\/24938289512.jpg\" \/><\/figure>\n<\/p>\n<p>eturn (<\/p>\n<p>\n<p>          {item}<\/p>\n<p>          <button title=\"Delete\"> {<\/p>\n<p><p>            allItems.splice(index, 1);<\/p>\n<p>            this.setState({ allItems });<\/p>\n<p>          }} \/&gt;<\/p>\n<p>        <\/button><\/p>\n<p>      );<\/p>\n<p>    });<\/p>\n<p>    return (<\/p>\n<p>  <a href=\"https:\/\/www.zhidianwl.com\/\">\u7f51\u7ad9\u505aapp<\/a>    <\/p>\n<p><p>          style={styles.input}<\/p>\n<p>          placeholder=&#8221;Add item&#8221;<\/p>\n<p>          value={inputText}<\/p>\n<p>          onChangeText={text =&gt; this.setState({ inputText: text })}<\/p>\n<p>        \/&gt;<\/p>\n<p>        <button title=\"Add\"><\/button><\/p>\n<p>\n<p>          {items}<\/p>\n<\/p>\n<p>    );<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>const styles = StyleSheet.create({<\/p>\n<p>  container: {<\/p>\n<p>    flex: 1,<\/p>\n<p>    justifyContent: &#8216;center&#8217;,<\/p>\n<p>    alignItems: &#8216;center&#8217;,<\/p>\n<p>    backgroundColor: &#8216;#F5FCFF&#8217;,<\/p>\n<p>  },<\/p>\n<p>  input: {<\/p>\n<p>    width: &#8216;80%&#8217;,<\/p>\n<p>    borderWidth: 1,<\/p>\n<p>    borderColor: &#8216;#000000&#8217;,<\/p>\n<p>    margin: 10,<\/p>\n<p>    padding: 10<\/p>\n<p>  },<\/p>\n<p>  list: {<\/p>\n<p>    flex: 1,<\/p>\n<p>    width: &#8216;80%&#8217;,<\/p>\n<p>    padding: 10<\/p>\n<p>  },<\/p>\n<p>  listItem: {<\/p>\n<p>    flexDirection: &#8216;row&#8217;,<\/p>\n<p>    justifyContent: &#8216;space-between&#8217;,<\/p>\n<p>    alignItems: &#8216;center&#8217;,<\/p>\n<p>    borderWidth: 1,<\/p>\n<p>    borderColor: &#8216;#000000&#8217;,<\/p>\n<p>    padding: 10<\/p>\n<p>  }<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u4e8e\u6dfb\u52a0\u548c\u5220\u9664\u9879\u76ee\u3002\u5f53\u7528\u6237\u70b9\u51fb\u201c\u6dfb\u52a0\u201d\u6309\u94ae\u65f6\uff0c\u5e94\u7528\u7a0b\u5e8f\u5c06\u5c06\u6587\u672c\u6846\u4e2d\u7684\u6587\u672c\u6dfb\u52a0\u5230\u6240\u6709\u9879\u76ee\u6570\u7ec4\u4e2d\u3002\u7136\u540e\uff0c\u5e94\u7528\u7a0b\u5e8f\u5c06\u91cd\u65b0\u6e32\u67d3\u9879\u76ee\u5217\u8868\u3002\u6bcf\u4e2a\u9879\u76ee\u90fd\u663e\u793a\u4e86\u5728\u5217\u8868\u9879\u4e2d\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u5220\u9664\u6309\u94ae\u3002\u5f53\u7528\u6237\u70b9\u51fb\u5220\u9664\u6309\u94ae\u65f6\uff0c\u9879\u76ee\u5c06\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\uff0c\u5e76\u5c06\u66f4<a href=\"https:\/\/www.zhidianwl.com\/\">\u667a\u7535\u745e\u521b<\/a>\u65b0\u540e\u7684\u9879\u76ee\u5217\u8868\u518d\u6b21\u5448\u73b0\u3002<\/p>\n<p>\u8fd9\u662fReact Native\u6784\u5efa\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u8981\u8fc7\u7a0b\u3002\u901a\u8fc7\u4f7f\u7528React Native\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528JavaScript\u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u4ee3\u7801\u91cd\u7528\u4e8eiOS\u548cAndroid\u5e73\u53f0\u3002\u6b64\u5916\uff0cReact Native\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u7ec4\u4ef6\u548c\u529f\u80fd\uff0c\u53ef\u7528\u4e8e\u6784\u5efa\u6f02\u4eae\u7684\u548c\u9ad8\u6548\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>React\u662fFacebook\u5f00\u53d1\u7684\u4e00\u79cdJavaScript\u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa\u7528\u6237\u754c\u9762\u3002\u5b83\u53ef\u4ee5\u8f7b\u677e\u5730\u6784\u5efa\u4ea4\u4e92\u5f0f\u7528\u6237\u754c\u9762\uff0c\u4f7f\u5f97\u6211\u4eec\u5f00\u53d1Web\u5e94\u7528\u66f4\u52a0\u9ad8\u6548\u53ef\u7ef4\u62a4\u3002\u5728\u8fd9\u91cc\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528React\u6765\u5f00\u53d1\u4e00\u4e2a\u79fb<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[24943,14,914,31880,322],"class_list":["post-45119","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-vueapp","tag-14","tag-914","tag-app","tag-322"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/45119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=45119"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/45119\/revisions"}],"predecessor-version":[{"id":45138,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/45119\/revisions\/45138"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=45119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=45119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=45119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}