如何将.md降价文件加载到react组件中?我通过谷歌搜索尝试了这么多npm库,我找不到一个好的解决方案.
我想加载.md文件,如:
render() {
<div>
<MarkDown src="about.md" />
</div>
}
Run Code Online (Sandbox Code Playgroud) 如何要求变量.我可以这样工作
var config={
example1 : require("example1/main.js"),
example2 : require("example2/main.js")
}
Run Code Online (Sandbox Code Playgroud)
当我用的时候
var modules=["example1","example2"]
_.each(modules,function(module){
require(module+"/main.js")
})
Run Code Online (Sandbox Code Playgroud)
此错误是"无法找到模块'example1/main.js"
我正在尝试使用 props 将图像 url 加载到组件中,但似乎 require 不能接受任何变量。但是,如果我给 require 一个纯文本作为参数,它就可以工作
这个给出了错误
在 webpackEmptyContext 中找不到模块“../assets/logo.png”(评估在 ./src/component
<template>
<div>
{{imagelink}}
<div style="width: 150px; height: 150px; background-color: red">
<img :src="imglink" alt="" height="150px" width="150px">
</div>
</div>
</template>
<script>
export default {
name: "ImageTest",
props:{
imagelink: String,
},
computed: {
imglink: function () {
// this.imagelink
const modulepatha = '../assets/logo.png'
return require(modulepatha)
}
}
}</script>
<style scoped>
</style>
Run Code Online (Sandbox Code Playgroud)
这个有效:
<template>
<div>
{{imagelink}}
<div style="width: 150px; height: 150px; background-color: red">
<img :src="imglink" alt="" height="150px" width="150px">
</div>
</div> …Run Code Online (Sandbox Code Playgroud)