vue-krpano icon indicating copy to clipboard operation
vue-krpano copied to clipboard

communication doesn't work

Open zhuyuanwen opened this issue 7 years ago • 4 comments

Hey, I just try krpano script and vue.js communication. And it doesn't work.

methods:{ doSomething(){ //do something console.log("doSomething"); } }

jscall(calc('krpano.hooks.doSomething()'));

There's no log show in console.

zhuyuanwen avatar May 18 '17 04:05 zhuyuanwen

create a hook object on your view model

{
    hooks: {
        doSomething(){
            console.log("do something)
        }
    }
}

assign the hooks object in your component markup

<krpano :hooks="hooks" ></krpano>

chshapple avatar May 18 '17 05:05 chshapple

@chshapple It works! Thanks!😃

zhuyuanwen avatar May 18 '17 14:05 zhuyuanwen

@chshapple How can I get the vue instance in doSomething() function? Now the 'this' in doSomething() function is an object, not vue instance. { hooks: { doSomething(){ console.log(this) console.log("do something") } } }

zhuyuanwen avatar May 19 '17 22:05 zhuyuanwen

@zhuyuanwen

export default {
        data () {
             const vm = this;
              return {            
                hooks: {
                   doSomething () {
                       console.log(vm)  //not this
                           }
                      }          
                  }
               }
           }

haoXu-web avatar Jul 10 '18 03:07 haoXu-web