import XmlViewer from ‘./XmlViewer‘ Module parse failed

<template>
    <button @click="toggle">Toggle Theme</button>
    <div style="padding-left: 20px; padding-top: 20px;">
        <XmlViewer :xml="xml" :theme="theme" />
    </div>
</template>

<script>
import XmlViewer from ./XmlViewer
import testXml from ../data/test2.xml

import { ref } from vue

export default {
    components: {
        XmlViewer
    },
    setup() {
        const xml = ref(testXml)
        const theme = ref(light)
        function toggle() {
            document.querySelector(body).style.backgroundColor = theme.value === light ? #111 : #fdfdfd
            theme.value = theme.value === light ? dark : light
        }

        return {
            xml,
            theme,
            toggle
        }
    }
}
</script>
ERROR  Failed to compile with 1 error                                                                                                         上午11:34:48

 error  in ./src/data/test2.xml

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <?xml version="1.0" encoding="utf-8"?>
| <RegisterDescription
|       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/xmlComponents/Test.vue?vue&type=script&lang=js 2:0-40 9:18-25
 @ ./src/xmlComponents/Test.vue?vue&type=script&lang=js
 @ ./src/xmlComponents/Test.vue
 @ ./src/router/index.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://10.16.2.191:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

全网仅此一篇 成功解决

ERROR Failed to compile with 1 error 上午11:34:48 error in ./src/data/test2.xml Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders > |
经验分享 程序员 微信小程序 职场和发展