vue中怎么用AlloyFinger?

vue里面如何引入触屏的AlloyFinger啊,看了官方的也不会弄,有报错,下面是我的代码:

// main.js
import Vue from 'vue'
import App from './App'
// 下面两种都试了,都报错
// import AlloyFingerVue from 'AlloyFinger'
// Vue.use(AlloyFingerVue)
import AlloyFinger from 'AlloyFinger'
Vue.use(AlloyFinger)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  template: '<App/>',
  components: { App }
})

报错信息

clipboard.png

阅读 8.7k
3 个回答

不是给你用法了吗

Vue.use(AlloyFingerVue); // use AlloyFinger's plugin

var h = new Vue({
    el: '#cnt',
    methods: {
        tap: function() { console.log('onTap'); },
        multipointStart: function() { console.log('onMultipointStart'); },
        longTap: function() { console.log('onLongTap'); },
        swipe: function(evt) {
            console.log("swipe" + evt.direction);
            console.log('onSwipe');
        },
        pinch: function(evt) { 
            console.log(evt.scale);
            console.log('onPinch'); 
        },
        rotate: function(evt) {
            console.log(evt.angle);
            console.log('onRotate'); 
        },
        pressMove: function(evt) { 
            console.log(evt.deltaX);
            console.log(evt.deltaY);
            console.log('onPressMove'); 
        },
        multipointEnd: function() { console.log('onMultipointEnd'); },
        doubleTap: function() { console.log('onDoubleTap'); },
        singleTap: function () { console.log('onSingleTap'); },

        touchStart: function() { console.log('onTouchStart'); },
        touchMove: function() { console.log('onTouchMove'); },
        touchEnd: function() { console.log('onTouchEnd'); },
        touchCancel: function() { console.log('onTouchCancel'); }
    }
});

你还需要创建一个 vue 实例,

/* eslint-disable no-unused-vars */
import AlloyFinger from 'alloyfinger/alloy_finger' // 手势库
import AlloyFingerVue from 'alloyfinger/vue/alloy_finger.vue'
Vue.use(AlloyFingerVue, {
  AlloyFinger
})
新手上路,请多包涵
/*可以当插件使用 main.js*/
import AlloyFinger from 'alloyfinger'
import AlloyFingerPlugin from 'alloyfinger/vue/alloy_finger.vue'
Vue.use(AlloyFingerPlugin,{
  AlloyFinger
})

/*.vue*/
<template>
    <div class="page-content" v-finger:swipe="swipeHandler">
      <transition name="fade">
        <router-view />
      </transition>
    </div>
</template>

finger是提供的插件里面提供的指令

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题