我在使用WebPack在我的React应用程序中使用解析别名时遇到困难,而我从谷歌搜索结果中尝试的所有内容似乎没有任何区别.
这是我对webpack的决心.
C:\网站\ webpack.config.js
resolve: {
extensions: ['*', '.js', '.jsx'],
alias: {
apiAlias: path.resolve(__dirname, '/app/services/api/')
}
}
Run Code Online (Sandbox Code Playgroud)
这是C:\ website\app\components\Accounts\Accounts.js
import ApiAccounts from '/apiAlias/ApiAccounts.js';
Run Code Online (Sandbox Code Playgroud)
我有一个位于C:\ website\app\services\api\ApiAccounts.js的文件将以上行改为以下作品:
import ApiAccounts from '../../services/api/ApiAccounts.js';
Run Code Online (Sandbox Code Playgroud)
为了丰满,这是我的webpack依赖项:
"devDependencies": {
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3",
"webpack-dev-server": "^3.1.4"
}
Run Code Online (Sandbox Code Playgroud)
但我一直得到错误
./app/components/Accounts/Accounts.js中的错误找不到模块:错误:无法解析'C:\ website\app\components\Accounts'中的'/apiAlias/ApiAccounts.js'
任何人都可以看到任何明显的我缺少的东西,或者应该尝试尝试让这个工作,或者即使有一种方法来调试webpack,看看它实际上使用的路径,如果别名实际上踢了?
谢谢!
我有以下示例代码,创建一个对象集合.
如何删除其中一个对象?(例如,$ TestList看起来似乎"删除我"项目从未出现过.我已经尝试过.remove,.splice,.delete等但我告诉它不是一个函数.
执行typeof($ TestList)会返回对象,而typeof($ TestList [0])也似乎有效.
当然,没有一件物品,我不必重新创建这个系列?
(function($) {
jQuery.QuickTest = {
$TestList: {},
build: function()
{
$TestList={};
$TestList[0] =
{
title: "part 1"
};
$TestList[1] =
{
title: "delete me please"
};
$TestList[2] =
{
title: "part 2"
};
}
}
jQuery.fn.QuickTest = jQuery.QuickTest.build;
})(jQuery);
$(document).ready(function() {
$().QuickTest(
{
})
});
Run Code Online (Sandbox Code Playgroud)
我们正在使用jQuery 1.3.
谢谢!
如何将多个参数传递给React中的函数?
以下似乎有意义,但只有数据才能检索到正确的信息.level已定义,但只是一个空对象.
<OutputContent data = { this.props.data } level = {0} />
function OutputContent({data}, level) {
console.log(data);
console.log(level);
return <p>A simple example</p>
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试遍历一个类及它的子类来获取与它一起传递的值.
这是我的班级:
public class MainClass
{
bool IncludeAdvanced { get; set; }
public ChildClass1 ChildClass1 { get; set; }
public ChildClass2 ChildClass2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码
GetProperties<MainClass>();
private void GetProperties<T>()
{
Type classType = typeof(T);
foreach (PropertyInfo property in classType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
WriteToLog(property.Name + ": " + property.PropertyType + ": " + property.MemberType);
GetProperties<property>();
}
}
Run Code Online (Sandbox Code Playgroud)
两个问题:
希望这一切都有意义.如果没有,请不要犹豫,我会尽力澄清.
谢谢