Css Selector in Framework7 vue

二次信任 提交于 2019-12-08 09:10:49

问题


i try to build an Cordova/Phonegap application using vue.js and the Framework7. I find out how to use functions like "onClick" using the "v-on:click="OnClick" attribute in an html element. Framework7 has jquery already implemented in the dom.

But there is one question. How can i access the dom directly, so that i can select whole css classes with the jquery selector. Like: $('.likeButton'). ?

In the offical framework7 i found something like this to access the dom with its functions:

this.$$ or this.Dom7

This is what i have already written down in the home.vue file:

    <script>


  //import Fonts-awesome Icons
  import FontAwesomeIcon from '@fortawesome/vue-fontawesome'
  import {} from '@fortawesome/fontawesome-free-solid'
  import F7Icon from "framework7-vue/src/components/icon";
  import F7PageContent from "framework7-vue/src/components/page-content";
  import * as Framework7 from "framework7";

  export default {
    name: 'FAExample',

    components: {
      F7PageContent,
      F7Icon,
      FontAwesomeIcon
    },
    methods: {
      clickit: function () {
        console.log("hi");

        //this is what i have tested, looking if i have access to dom
        let $$ = this.$$;
        console.log($$);
      },
      //this is what i want to use
      $('.likebutton').on('click',function () {

  })
  }


  }


</script>

Did any of you have an idea how this works? I hope you can help me. I'm new with vue.js in combination with the framework7.

Thank's for your help :)


回答1:


We can use all the DOM functions just like

this.$$('.classname)

for example, if you want to hide something by jquery you can use as:

this.$$('.classname).hide()

To check all the DOM functions you can check the official documentation. https://framework7.io/docs/dom7.html

But make sure that your DOM function should not in any Window function. If you get the error to implemented it, just make the 'this' instance first.

Just like: var self=this; // a global variable with this instance use

self.$$('.classname).hide()

for any framework7 help, just ping me on skyp: sagardhiman5_1




回答2:


Have you tried using Vue's $refs? You can set a reference to a specific DOM element and then access that in Vue.

A simple example:

<template>
  <div class="some-item" ref="itemRef">Some item</div>
</template>

Then in the component:

var myItem = this.$refs.myItem;
// do what you want with that DOM item...

You can also access $refs from the parent. The example in the link below gives details on that.

More on $refs: https://vuejs.org/v2/guide/components.html#Child-Component-Refs



来源:https://stackoverflow.com/questions/49087044/css-selector-in-framework7-vue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!