简体   繁体   English

Vue native 总是执行 App.js 而不是.vue

[英]Vue native is always executing App.js instead of .vue

I made the first process of installation of vue-native, and I'm following the "Getting Started" Hello world tutorial ( https://vue-native.io/getting-started.html ), but the App.vue is never executed, only the App.js .我完成了 vue-native 安装的第一个过程,我正在按照“入门”Hello world 教程( https://vue-native.io/getting-started.html )进行操作,但App.vue永远不会执行,只有App.js If I remove the App.js I get an error:如果我删除App.js ,我会收到错误消息:

"Unable to resolve "../../App" from "node_modules\expo\AppEntry.js"" “无法从“node_modules\expo\AppEntry.js”解析“../../App””

How can I fix this problem to make it work and follow the tutorial with any problem?如何解决此问题以使其正常工作并按照教程处理任何问题?

Folder Structure:文件夹结构:

在此处输入图像描述

App.js应用程序.js

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>Open up App.js to start working on your app!</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

App.vue App.vue

<template>
  <view class="container">
    <text class="text-color-primary">My Vue Native App</text>
    </view>
</template>

<style>
.container {
  background-color: white;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.text-color-primary {
  color: blue;
}
</style>

Thank you谢谢

Although the answers might work for some.尽管答案可能对某些人有用。 There is another way to fix this issue without deleting any files.还有另一种方法可以在不删除任何文件的情况下解决此问题。 Navigate to the node modules folder.导航到节点模块文件夹。 Search for the expo folder.搜索 expo 文件夹。

Open the AppEntry.js file.打开AppEntry.js文件。 It should look like this:它应该是这样的:

import 'expo/build/Expo.fx';
import registerRootComponent from 'expo/build/launch/registerRootComponent';
import { activateKeepAwake } from 'expo-keep-awake';

import App from '../../App'; // we will change this!

if (__DEV__) {
  activateKeepAwake();
}

registerRootComponent(App);

Modify Appentry.js to this:将 Appentry.js修改为:

import 'expo/build/Expo.fx';
import registerRootComponent from 'expo/build/launch/registerRootComponent';
import { activateKeepAwake } from 'expo-keep-awake';

import App from '../../App.vue'; // Will use App.vue as the entry point

if (__DEV__) {
  activateKeepAwake();
}

registerRootComponent(App);

The following worked for me:以下对我有用:
At first you delete app.js This will give you an error, but don't worry.一开始你删除app.js这会给你一个错误,但不要担心。 You will have to run the npm install command.您将必须运行npm install命令。 After this, run vue-native again with npm start之后,使用npm start再次运行 vue-native

This will run the app.vue file normally这将正常运行 app.vue 文件

Had a same issue.有同样的问题。 Below works for me下面对我有用

In app.json add在 app.json 添加

"sourceExts": [ "js", "json", "ts", "tsx", "jsx", "vue"]

Inside "packagerOpts"在“packagerOpts”里面

"packagerOpts": { "sourceExts": [ "js", "json", "ts", "tsx", "jsx", "vue"], "config": "metro.config.js"}

Read it from: https://github.com/GeekyAnts/vue-native-core/issues/117阅读自: https ://github.com/GeekyAnts/vue-native-core/issues/117

If you are viewing on web browser(which isn't production ready), i think it will look for App entry file in this order js > json > vue.如果您在网络浏览器上查看(尚未准备好生产),我认为它会按 js > json > vue.js 的顺序查找应用程序入口文件。 So i think it's impossible it will seek out App.vue.所以我认为它不可能寻找 App.vue。

For viewing on android phone, stop the Expo Dev Tools in terminal, delete App.js, then run npm start order or npm run android要在 android 手机上查看,请在终端中停止 Expo Dev Tools,删除 App.js,然后运行npm start ordernpm run android

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM