Gcanvas-For-Apache-weex
Gcanvas-For-Apache-weex copied to clipboard
跟着当前的文档指引,无法成功运行该项目。
过程描述
使用 weex 创建全新的项目,并添加该 plugin:
weex create test
cd test && weex platform add ios
weex plugin add weex-gcanvas
打开 platforms/ios/WeexDemo.xcworkspace 无法正确编译。
修改 platforms/ios/Podfile 添加 pod 'GCanvas', '0.0.5'
之后才编译通过。推测是因为默认使用了最新的 0.0.6 版本,与当前版本不兼容。这里显示了该项目版本管理混乱的问题,其实只要在 podspec 里指定明确的版本就不会发生这种问题了。
将 src/index.vue 改为以下内容(从该项目的 examples/singlecanvas 复制):
<template>
<div id="test">
<gcanvas id="canvas_holder" style="width:750;height:750;"></gcanvas>
</div>
</template>
<script>
var GCanvas=require('weex-gcanvas');
module.exports = {
created: function () {
GCanvas.disable();
},
mounted: function () {
console.log("mounted")
var ref = this.$refs.canvas_holder;
var gcanvas = GCanvas.start(ref);
var ctx = gcanvas.getContext('2d');
//rect
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 100, 100);
//rect
ctx.fillStyle = 'black';
ctx.fillRect(100, 100, 100, 100);
ctx.fillRect(25, 210, 700, 5);
//circle
ctx.arc(450, 200, 100, 0, Math.PI * 2, true);
ctx.fill();
}
}
</script>
运行时报 TypeError: undefined is not an object (evaluating 't.ref')
,目前仍未找到原因。
遗憾的是,从 examples 里拿来的代码有非常多低级错误,会报各种 undefined 的错,例如
// var gcanvas=require('weex-gcanvas'); //正式使用请用这个
var GCanvas=require('../js/src/gcanvas'); //调试使用
里面被注释掉的、正式使用的 gcanvas 其实应该改为 GCanvas。
建议
该项目目前主要以 weex plugin 的方式对外提供,但是按照 weex plugin 的方式都无法将该项目成功运行。而以 pod 的方式使用该项目的时候,则会报各种版本的问题 #28 ,同样无法正常使用。示例代码也没有一个唯一的、正确的版本,要验证项目非常困难。
建议控制好版本,并保证第一次使用的人能跟着文档指引跑通该项目。
在created(){}里面使用 GCanvas.disable();是提示
<Weex>[error]WXJSCoreBridge.m:134, jsLog: TypeError: GCanvas.disable is not a function. (In 'GCanvas.disable()', 'GCanvas.disable' is undefined) \^[[;
TypeError: undefined is not an object (evaluating 't.ref') 这个问题 找到原因了吗