我正在玩流星的“thospaeth:color-thief”套餐。 我所做的只是安装包,然后在事件处理程序中定义一个变量:
var colorThief = new ColorThief();
错误是
"Exception in template helper: ReferenceError: ColorThief is not defined
at Object.Template.onePiece.helpers.image (http://localhost:3000/test.js?5fb2bf210aaa5b8ff2677599dea86a243ed2c4ef:689:27)
at bindDataContext (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2880:16)
at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:1651:16)
at http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2928:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:12)
at wrapHelper (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2927:27)
at Spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18)
at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:109:25)
at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:113:39)
at null._render (http://localhost:3000/template.test.js?99a11da3988b8831f8e1fc0dcbf93b61fa67d909:281:22)"
我尝试了另一个包“benan789:color-thief”。它没用。 我试图将colorthief.js复制到文件夹,然后直接将其包含在标题中。它也没用。
我错过了什么吗?在此先感谢您的帮助。
答案 0 :(得分:0)
我无法得到thospaeth:颜色小偷也在工作,但是benan789:颜色小偷工作。请注意流星使用说明(https://atmospherejs.com/benan789/color-thief):
var colorThief = new ColorThief.colorRob();
您的事件处理程序可能如下所示:
'click button': function () {
var colorThief = new ColorThief.colorRob();
// get a handle on an image element
var headerImage = $('img.headerimage')[0];
// get the dominant color from the image
var c = colorThief.getColor(headerImage);
console.log('color: ' + c);
}