繁体   English   中英

在 Vue.js 文件中使用 JS/JQuery

[英]Using JS/JQuery in Vue.js files

我们不能在 vue.js 中使用我们自定义的 JS 代码吗? 我想添加基本的 jquery 和 JS 代码,但似乎 vue.js 不接受它。 我需要为它创建组件吗?

这是我要添加的js代码

<head>
  <title>Pusher Test</title>
  <script src="https://js.pusher.com/5.1/pusher.min.js"></script>
  <script>

    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;

    var pusher = new Pusher('ID', {
      cluster: 'ap2',
      forceTLS: true
    });

    var channel = pusher.subscribe('my-channel');
    channel.bind('my-event', function(data) {
      alert(JSON.stringify(data));
    });
  </script>
</head>
<body>
  <h1>Pusher Test</h1>
  <p>
    Try publishing an event to channel <code>my-channel</code>
    with event name <code>my-event</code>.
  </p>
</body>

这就是我的 vue.js 代码开始的方式,我的印象是它可以毫无问题地工作。

    <template>
    <div>  
    <div class="apps-backdrop in" @click="close" v-if="isOpen"></div>
    <div class="apps-sidebar" :class="{'in': isOpen}">
      <v-list three-line class="navy pa-0 pt-2">
        <v-subheader>
          <h3>Title</h3>
        </v-subheader>

        .....



<script>


import hopscotch from 'hopscotch';
import { mapActions, mapState } from 'vuex';
import sites from '../../config/sites';
import api from '../api/users';


export default {
    name: 'pushercomponent',
    data () {

....

安装后:

npm install jquery --save

在您想要的任何组件中导入 jQuery:

<script>
  import $ from 'jquery';

  export default {
    mounted() {
      $(".test").delay(3000).css("background-color","red");
    },
  };
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM