加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 如何使用React Native矢量图标?

发布时间:2020-12-15 20:45:28 所属栏目:百科 来源:网络整理
导读:我刚用这个命令安装了 React Native vector icons: npm install react-native-vector-icons 但是如果我在index.android.js中使用它 Icon name="ios-add" size={30} color="#4F8EF7" / 我得到一个正方形,中间有一个X而不是图标. 为什么? 编辑: 如果我尝试
我刚用这个命令安装了 React Native vector icons:
npm install react-native-vector-icons

但是如果我在index.android.js中使用它

<Icon name="ios-add" size={30} color="#4F8EF7" />

我得到一个正方形,中间有一个X而不是图标.

为什么?

编辑:

如果我尝试使用“npm install react-native-vector-icons –save”安装它,那么我收到此错误:

C:UsersxrobotDesktopReact NativeAwesomeProject>npm install react-native-vector-icons --save

    npm ERR! Windows_NT 10.0.14393
    npm ERR! argv "C:Program Filesnodejsnode.exe" "C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js" "install" "react-native-vector-icons" "--save"
    npm ERR! node v6.9.5
    npm ERR! npm  v3.10.10
    npm ERR! path C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modules.stagingreact-native-vector-icons-73f301e7
    npm ERR! code EPERM
    npm ERR! errno -4048
    npm ERR! syscall rename

    npm ERR! Error: EPERM: operation not permitted,rename 'C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modules.stagingreact-native-vector-icons-73f301e7' -> 'C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modulesreact-native-vector-icons'
    npm ERR!     at destStatted (C:Program Filesnodejsnode_modulesnpmlibinstallactionfinalize.js:25:7)
    npm ERR!     at C:Program Filesnodejsnode_modulesnpmnode_modulesgraceful-fspolyfills.js:264:29
    npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
    npm ERR!
    npm ERR! Error: EPERM: operation not permitted,rename 'C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modules.stagingreact-native-vector-icons-73f301e7' -> 'C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modulesreact-native-vector-icons'
    npm ERR!     at Error (native)
    npm ERR!  { Error: EPERM: operation not permitted,rename 'C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modules.stagingreact-native-vector-icons-73f301e7' -> 'C:UsersemilianoDesktopReact NativeAwesomeProjectnode_modulesreact-native-vector-icons'
    npm ERR!     at destStatted (C:Program Filesnodejsnode_modulesnpmlibinstallactionfinalize.js:25:7)
    npm ERR!     at C:Program Filesnodejsnode_modulesnpmnode_modulesgraceful-fspolyfills.js:264:29
    npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
    npm ERR!
    npm ERR! Error: EPERM: operation not permitted,rename 'C:UsersemilianoDesktopReact NativeAwesomeProjectnode_modules.stagingreact-native-vector-icons-73f301e7' -> 'C:UsersxrobotDesktopReact NativeAwesomeProjectnode_modulesreact-native-vector-icons'
    npm ERR!     at Error (native) parent: 'AwesomeProject' }
    npm ERR!
    npm ERR! Please try running this command again as root/Administrator.

    npm ERR! Please include the following file with any support request:
    npm ERR!     C:UsersxrobotDesktopReact NativeAwesomeProjectnpm-debug.log

    C:UsersxrobotDesktopReact NativeAwesomeProject>npm install react-native-vector-icons
    AwesomeProject@0.0.1 C:UsersxrobotDesktopReact NativeAwesomeProject
    `-- react-native-vector-icons@4.0.0

编辑2:

C:UsersxrobotDesktopReact NativeAwesomeProject>react-native link react-native-vector-icons
rnpm-install info Linking react-native-vector-icons android dependency
rnpm-install info Android module react-native-vector-icons has been successfully linked
rnpm-install info Linking react-native-vector-icons ios dependency
rnpm-install info iOS module react-native-vector-icons has been successfully linked
rnpm-install info Linking assets to ios project
rnpm-install WARN ERRGROUP Group 'Resources' does not exist in your XCode project. We have created it automatically for you.
rnpm-install info Linking assets to android project
rnpm-install info Assets have been successfully linked to your project

编辑3:

我已经从物理设备中删除了应用程序,然后我重新构建它(正如QMFNP所说).现在它有效

首先,确保通过执行以下操作来保存项目中的依赖项:

npm install react-native-vector-icons –save.包括–save是必要的,否则react-native链接将无法定位模块.

在iOS或Android项目中使用它们之前,还必须链接本机模块.快速执行此操作的方法是使用以下命令:

react-native链接react-native-vector-icons

如果由于任何原因您在使用react-native链接链接本机模块时遇到问题,react-native-vector-icons README还提供了在Android和iOS上手动链接它们以及在Web上集成库的详细说明.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读