gpt4 book ai didi

javascript - Laravel 中 VueJS 组件实现中的鼠标悬停

转载 作者:搜寻专家 更新时间:2023-10-30 22:09:57 26 4
gpt4 key购买 nike

当我在 Laravel 上使用它时,我的鼠标悬停不起作用。

我的Vue文件存放在resources/js/Dashboard.vue

到目前为止我尝试的是将 v-on:mouseover 更改为 @mouseover 但它仍然不起作用。

结果是,当我将鼠标悬停在按钮上时,它不会更改文本。

我做错了什么,我该如何解决?

下面是我的 Dashboard.vue 文件的内容;

<template>
<div id="mouse">
<a
v-on:mouseover="mouseover"
v-on:mouseleave="mouseleave">
{{message}}
</a>
</div>
</template>
<!--Force Override of the css style for datepicker class-->

<style>

#mouse {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: block;
width: 280px;
height: 50px;
margin: 0 auto;
line-height: 50px;
text-align: center;
color: #fff;
background: #007db9;
}
</style>

<script>

export default {
components: {
},
data() {
return {
showAudience: false,
message: 'Hover Me',
}
},
computed: {
},
methods : {
mouseover: function(){
this.message = 'Good!'
},
mouseleave: function(){
this.message = 'Hover Me!'
}
},
mounted() {
},
}
</script>

这里是我的 Blade.php 文件的内容;

@extends('layouts.app', ['pageSlug' => 'dashboard'])

@section('content')
<dashboard-component></dashboard-component>
@endsection

@push('js')
<script src="{{ asset('black') }}/js/plugins/chartjs.min.js"></script>
<script src="{{ asset('js/app.js') }}"></script>
<script>
$(document).ready(function() {
//demo.initDashboardPageCharts();
});
</script>
@endpush

仔细查看并在本地复现,下面是package.json文件;

{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.1.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^7.1.0",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"chart.js": "^2.8.0",
"friendly-errors-webpack-plugin": "npm:@soda/friendly-errors-webpack-plugin@^1.7.1",
"vue-chartjs": "^3.4.2",
"vue2-datepicker": "^2.12.0"
}
}

编辑添加了我的 app.js

require('./bootstrap');
window.Vue = require('vue');
import Vue from 'vue'
import App from './components/App.vue'

/**
* The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue
* components and automatically register them with their "basename".
*
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
*/

// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));
Vue.component('dashboard-component', require('./components/Dashboard.vue').default);
Vue.component('base-table', require('./components/base/BaseTable.vue'));

Vue.component('example-component', require('./components/ExampleComponent.vue').default);


new Vue({
el: '#app',
});

最佳答案

尝试添加这些以防止默认事件和传播

v-on:mouseover.prevent.stop="mouseover"
v-on:mouseleave.prevent.stop="mouseleave"

关于javascript - Laravel 中 VueJS 组件实现中的鼠标悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58025504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com