Skip to content

Commit

Permalink
fix(cli): fix bind missing a ":"
Browse files Browse the repository at this point in the history
fix #2497
  • Loading branch information
Gcaufy committed Feb 9, 2020
1 parent f5fb220 commit 4fd87d2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/cli/core/plugins/template/directives/v-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const parseHandler = (name = '', value = '', scope) => {
info = parseHandlerProxy(value, scope);

if (name === 'click') name = 'tap';
type = 'bind' + name;
type = 'bind:' + name;
return {
event: name,
type: type,
Expand All @@ -93,7 +93,7 @@ exports = module.exports = function() {

this.register('template-parse-ast-attr-v-on.capture', function({ item, name, expr, event, scope, ctx }) {
// bind:tap="xxx" or catch:tap="xxx"
event.type = event.type.replace(/^bind/, 'bind:').replace(/^catch/, 'catch:');
event.type = event.type.replace(/^bind/, 'bind').replace(/^catch/, 'catch');
event.type = 'capture-' + event.type;
return { item, name, expr, event, scope, ctx };
});
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/test/core/fixtures/template/assert/v-on.wxml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<view data-wpy-evt="0-0" bindtap="_proxy"></view>
<view data-wpy-evt="0-1" catchtap="_proxy"></view>
<view data-wpy-evt="0-0" bind:tap="_proxy"></view>
<view data-wpy-evt="0-1" catch:tap="_proxy"></view>
<view data-wpy-evt="0-2" capture-bind:tap="_proxy"></view>
<view data-wpy-evt="0-3" capture-catch:tap="_proxy"></view>
<view data-wpy-evt="0-4" capture-catch:tap="_proxy"></view>

<view data-wpy-evt="0-5" bindtap="_proxy"></view>
<view data-wpy-evt="0-5" bind:tap="_proxy"></view>

<view wx:for="{{ list }}" wx:for-index="index" wx:for-item="item" wx:key="index">
<button data-wpy-evt="0-6" bindtap="_proxy" data-wpytap-a="{{ item }}"></button>
<button data-wpy-evt="0-6" bind:tap="_proxy" data-wpytap-a="{{ item }}"></button>
</view>

<view data-wpy-evt="0-7" capture-bind:tap="_proxy"></view>
<view data-wpy-evt="0-8" capture-catch:tap="_proxy"></view>

<view data-wpy-evt="0-9" bind:click-right="_proxy"></view>
4 changes: 2 additions & 2 deletions packages/cli/test/core/fixtures/template/assert/v-on.wxs.wxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<view bindtap="{{ m.touchmove }}"></view>
<view data-wpy-evt="0-0" bindtap="_proxy"></view>
<view bind:tap="{{ m.touchmove }}"></view>
<view data-wpy-evt="0-0" bind:tap="_proxy"></view>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function proxy() {
var $event = arguments[arguments.length - 1];
var _vm = this;
return (function() {
_vm.rightNavbar($event);
})();
}
2 changes: 2 additions & 0 deletions packages/cli/test/core/fixtures/template/original/v-on.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

<div capture-bind:tap="handleCaptureBindTap"></div>
<div capture-catch:tap="handleCaptureCatchTap"></div>

<div @click-right="rightNavbar"></div>

1 comment on commit 4fd87d2

@Asces
Copy link

@Asces Asces commented on 4fd87d2 Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

微信运行库版本要求 2.8.0 bind:xxxx 这种写法 针对自定义事件与非自定义事件 才通用支持

Please sign in to comment.