[英]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.