live2d-widget icon indicating copy to clipboard operation
live2d-widget copied to clipboard

默认modelId为1会导致在模型只有一个的情况下无法正确加载模型

Open wuuconix opened this issue 1 year ago • 1 comments

问题代码: https://github.com/stevenjoezhang/live2d-widget/blob/ae27493c29391e0cf2e9c08d27ab9d466f0a9c93/src/index.js#L134 本项目默认加载modelId为1的模型。 当使用cdn方式加载模型时,modelId将作为数组下标。 https://github.com/stevenjoezhang/live2d-widget/blob/ae27493c29391e0cf2e9c08d27ab9d466f0a9c93/src/model.js#L32 而当cdn中只有一个模型时,this.modelList.models 这个数组将只存在一个元素,即下标为0的那个元素 而默认modelId默认为1,故this.modelList.models[1]将返回undefined。 这最终导致target这个原本应该是模型名称的变量成为undefined。

image

复现页面: https://codepen.io/wuuconix/pen/RwYeKPm 将默认modelId设置为0后的效果: https://codepen.io/wuuconix/pen/abaRpEQ

wuuconix avatar Mar 21 '23 15:03 wuuconix