Vue bind style dynamic backgroundImage with parameter using asset - vue.js

I'm trying to bind background images dynamically but there seems to be trouble compiling the assets. What's weird is that it works but no at the same time.
I've tried various solutions from SO and nothing get rids of the compilation error (which still compile based on the image above):
Vue.js dynamic images not working
VueJS v-bind:style for background-image: url()
Vue.js data-bind style backgroundImage not working
reference assets with generated style data bind
Vue dynamic background image inline component
How The Project is Set Up
Laravel Sanctum as the backend, Vue SPA for the frontend and utilising Axios for communications.
Topic.vue Component
<div
v-for="topic in topics"
:key="topic.id"
class="col-12 col-sm-6 col-lg-3 mb-4 d-flex justify-content-center"
>
<div
class="card-topic d-flex align-items-end"
:style="inlineBgImage(topic.src)"
>
<div class="card-topic__button py-3 text-center w-100">
<a href class="card-topic__link">{{ topic.title }}</a>
</div>
</div>
</div>
Script in Topic.vue
<script>
import { mapState } from 'vuex'
export default {
computed: {
...mapState('topic', ['topics']),
},
created() {
this.$store.dispatch('topic/fetchTopics')
},
methods: {
inlineBgImage(src) {
let bgImage = require('#/assets' + src)
return {
backgroundImage: `url("${bgImage}")`,
}
},
},
}
</script>
In the inlineBgImage(src) methods, the background-image is successfully applied if the require is hardcoded i.e. let bgImage = require('#/assets/img/topic/myself.jpg'). Once I used the src value, it broked but still works(Failed to compile. page appear)
Assets
Below is the asset folder structure
All SCSS files are imported to app.scss which are then imported to main.js
_variables.scss
The "undefined variable" does exist
app.scss
This is how I import the _variable.scss file in app.scss; #import 'variables.scss';. The import comes first before other files.
I've also tried:
#import 'variables';
#import '_variables';
#import '_variables.scss';
It still gives out errors.
Error Details in Terminal
I want to reiterate that these errors does not appear if I hardcode the bgImage e.g. require('#/assets/img/topic/myself.jpg'). I don't understand how these changes affect the compiler.
ERROR Failed to compile with 6 errors 12:37:58 PM
error in ./src/assets/scss/card.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
16 │ background-color: $dark-blue;
│ ^^^^^^^^^^
╵
src\assets\scss\card.scss 16:23 root stylesheet
# ./src/assets/scss/card.scss 4:14-233 14:3-18:5 15:22-241
# ./src sync ^\.\/assets.*$
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.100.14:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
error in ./src/assets/scss/search.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
27 │ color: $blue;
│ ^^^^^
╵
src\assets\scss\search.scss 27:12 root stylesheet
# ./src/assets/scss/search.scss 4:14-235 14:3-18:5 15:22-243
# ./src sync ^\.\/assets.*$
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.100.14:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
error in ./src/assets/scss/image.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
33 │ color: $white;
│ ^^^^^^
╵
src\assets\scss\image.scss 33:12 root stylesheet
# ./src/assets/scss/image.scss 4:14-234 14:3-18:5 15:22-242
# ./src sync ^\.\/assets.*$
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.100.14:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
error in ./src/assets/scss/button.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
2 │ color: $light-blue;
│ ^^^^^^^^^^^
╵
src\assets\scss\button.scss 2:12 root stylesheet
# ./src/assets/scss/button.scss 4:14-235 14:3-18:5 15:22-243
# ./src sync ^\.\/assets.*$
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.100.14:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
error in ./src/assets/scss/header.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
4 │ background-color: $dark-blue;
│ ^^^^^^^^^^
╵
src\assets\scss\header.scss 4:23 root stylesheet
# ./src/assets/scss/header.scss 4:14-235 14:3-18:5 15:22-243
# ./src sync ^\.\/assets.*$
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.100.14:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
error in ./src/assets/scss/nav.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
6 │ color: $light-blue;
│ ^^^^^^^^^^^
╵
src\assets\scss\nav.scss 6:12 root stylesheet
# ./src/assets/scss/nav.scss 4:14-232 14:3-18:5 15:22-240
# ./src sync ^\.\/assets.*$
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue?vue&type=script&lang=js&
# ./src/views/Topic.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.100.14:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
Other Details
The topic.src from v-for="topic in topics" will yield a String, for e.g. /img/topic/myself.jpg.

inlineBgImage(src) {
let fileExt = src.substring(src.lastIndexOf('.'))
src = src.replace('/img/', '')
src = src.replace(fileExt, '')
let bgImage = require('#/assets/img/' + src + fileExt)
return {
backgroundImage: `url("${bgImage}")`,
}
}
Kudos to skirtle for giving a solution at forum.vuejs.org. As skirtle mentioned, Webpack handles expression and fixed string parameter differently. I did change the solution a bit in case future files have different file extension. You see skirtle original answer and explanation there.

Related

How can I use vue-monaco?

I'm trying to implement vue-monaco, but I get these errors:
ERROR Failed to compile with 2 errors 4:59:58 PM
error in ./node_modules/monaco-editor/esm/vs/basic-languages/_.contribution.js
Module parse failed: Unexpected token (37:13)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| return lazyLanguageLoaders[languageId];
| }
> _languageId;
| _loadingTriggered;
| _lazyLoadPromise;
# ./node_modules/monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution.js 9:0-56 10:0-16
# include-loader!./node_modules/vue-monaco/node_modules/monaco-editor/esm/vs/editor/editor.main.js
# ./node_modules/vue-monaco/dist/vue-monaco.es.js
# ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/PlaygroundView.vue?vue&type=script&lang=js&
# ./src/views/PlaygroundView.vue?vue&type=script&lang=js&
# ./src/views/PlaygroundView.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://X.X.X.X:8081&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
error in ./node_modules/monaco-editor/esm/vs/language/typescript/monaco.contribution.js
Module parse failed: Unexpected token (76:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| })(ModuleResolutionKind || {});
| var LanguageServiceDefaultsImpl = class {
> _onDidChange = new monaco_editor_core_exports.Emitter();
| _onDidExtraLibsChange = new monaco_editor_core_exports.Emitter();
| _extraLibs;
# include-loader!./node_modules/vue-monaco/node_modules/monaco-editor/esm/vs/editor/editor.main.js 101:0-92
# ./node_modules/vue-monaco/dist/vue-monaco.es.js
# ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/PlaygroundView.vue?vue&type=script&lang=js&
# ./src/views/PlaygroundView.vue?vue&type=script&lang=js&
# ./src/views/PlaygroundView.vue
# ./src/router/index.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://X.X.X.X:8081&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
I think these issues are related to my vue.config.js; this is it:
const MonacoEditorPlugin = require('monaco-editor-webpack-plugin')
module.exports = {
transpileDependencies: [
'vuetify'
],
configureWebpack: {
plugins: [
new MonacoEditorPlugin({
languages: ['javascript', 'typescript']
})
],
},
}
Component implementation is almost identical to the guide. The guide seems pretty straightforward, so what am I doing wrong?
P.S. I even tried monaco-editor-vue, but I got almost the same errors.
To make it work I had to downgrade monaco-editor-webpack-plugin to 1.9.1; related link here. Note that typescript language is also needed, even though you want only javascript; related link here.

How to setup vuetify with vuetify-loader

I'm getting the error below when I run yarn serve:
ERROR Failed to compile with 1 errors 4:03:58 p.m.
error in ./node_modules/vuetify/src/styles/main.sass
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Expected identifier.
╷
34 │ .v-application .red.#ef4321{
│ ^
╵
node_modules/vuetify/src/styles/generic/_colors.scss 34:29 #import
node_modules/vuetify/src/styles/generic/_index.scss 2:9 #import
/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/vuetify/src/styles/main.sass 6:9 root stylesheet
# ./node_modules/vuetify/src/styles/main.sass 4:14-194 14:3-18:5 15:22-202
# ./node_modules/vuetify/lib/presets/default/index.js
# ./node_modules/vuetify/lib/services/presets/index.js
# ./node_modules/vuetify/lib/services/index.js
# ./node_modules/vuetify/lib/framework.js
# ./node_modules/vuetify/lib/index.js
# ./src/plugins/vuetify.js
# ./src/main.js
# ./src/entry-client.js
# multi webpack-hot-middleware/client ./src/entry-client
Client errors
./node_modules/vuetify/src/styles/main.sass (./node_modules/css-loader/dist/cjs.js??ref--9-oneOf-3-1!./node_modules/postcss-loader/src??ref--9-oneOf-3-2!./node_modules/sass-loader/dist/cjs.js??ref--9-oneOf-3-3!./node_modules/vuetify/src/styles/main.sass)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Expected identifier.
╷
34 │ .v-application .red.#ef4321{
│ ^
╵
node_modules/vuetify/src/styles/generic/_colors.scss 34:29 #import
node_modules/vuetify/src/styles/generic/_index.scss 2:9 #import
/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/vuetify/src/styles/main.sass 6:9 root stylesheet
SassError: SassError: Expected identifier.
╷
34 │ .v-application .red.#ef4321{
│ ^
╵
node_modules/vuetify/src/styles/generic/_colors.scss 34:29 #import
node_modules/vuetify/src/styles/generic/_index.scss 2:9 #import
/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/vuetify/src/styles/main.sass 6:9 root stylesheet
at /Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass-loader/dist/index.js:73:16
at Function.call$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:88152:16)
at _render_closure1.call$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:77577:12)
at _RootZone.runBinary$3$3 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:26142:18)
at _RootZone.runBinary$3 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:26146:19)
at _FutureListener.handleError$1 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24590:19)
at _Future__propagateToListeners_handleError.call$0 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24887:40)
at Object._Future__propagateToListeners (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:4311:88)
at _Future._completeError$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24715:9)
at _AsyncAwaitCompleter.completeError$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24107:12)
at Object._asyncRethrow (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:4065:17)
at /Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:14085:20
at _wrapJsFunctionForAsync_closure.$protected (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:4090:15)
at _wrapJsFunctionForAsync_closure.call$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24128:12)
at _awaitOnObject_closure0.call$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24120:25)
at _RootZone.runBinary$3$3 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:26142:18)
at _RootZone.runBinary$3 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:26146:19)
at _FutureListener.handleError$1 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24590:19)
at _Future__propagateToListeners_handleError.call$0 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24887:40)
at Object._Future__propagateToListeners (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:4311:88)
at _Future._completeError$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24715:9)
at _AsyncAwaitCompleter.completeError$2 (/Users/markshaio/Desktop/Sirius/SRS-772-new/sirius_02/node_modules/sass/sass.dart.js:24107:12)
# ./node_modules/vuetify/src/styles/main.sass 4:14-194 14:3-18:5 15:22-202
# ./node_modules/vuetify/lib/presets/default/index.js
# ./node_modules/vuetify/lib/services/presets/index.js
# ./node_modules/vuetify/lib/services/index.js
# ./node_modules/vuetify/lib/framework.js
# ./node_modules/vuetify/lib/index.js
# ./src/plugins/vuetify.js
# ./src/main.js
# ./src/entry-client.js
# multi webpack-hot-middleware/client ./src/entry-client
webpack built 3690c6dc81708ab4b923 in 2915ms
I believe it has to do with vuetify-loader setup with Vuetify but I'm not sure what I'm doing wrong here. I've setup vuetify using webpack as specified here: https://vuetifyjs.com/en/getting-started/installation/#webpack-install
I also tried to modify webpack.config.js to match what is shown by the vuetify-loader docs: https://github.com/vuetifyjs/vuetify-loader,
const { VuetifyLoaderPlugin } = require('vuetify-loader')
exports.plugins.push(
new VuetifyLoaderPlugin()
)
However I'm not having any luck. I know I can also do the installation other ways but the reason I'm using the vuetify-loader is because I need to import specific vuetify components such that the vuetify styling doesn't break the styling of an existing project.

BootstrapVue Unknown word Error in ./node_modules/bootstrap-vue/src/index.scss

i would like to use bootstrap vue with my own scss file for theming.
Unfortunately I always get a strange error:
ERROR Failed to compile with 1 error
error in ./node_modules/bootstrap-vue/src/index.scss
Syntax Error: SyntaxError
(1:1) Unknown word
> 1 | // --- BootstrapVue Custom SCSS ---
| ^
2 |
3 | // Requires at least the Bootstrap functions, variables and
# ./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--6-oneOf-1-2!./src/assets/custom.scss 4:40-286
# ./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--6-oneOf-1-2!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=style&index=0&lang=css&
# ./node_modules/vue-style-loader??ref--6-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--6-oneOf-1-2!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=style&index=0&lang=css&
# ./src/App.vue?vue&type=style&index=0&lang=css&
# ./src/App.vue
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.1.20:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
For the structure I followed exactly the docs
My custom.scss File:
$theme-colors: (
"primary": #51ff00,
"danger": #ff4136
);
#import '../../node_modules/bootstrap/scss/bootstrap.scss';
#import '../../node_modules/bootstrap-vue/src/index.scss';
and the main.js File:
// ***** Bootstrap Vue *****
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
import './assets/custom.scss'
Vue.use(BootstrapVue)
Vue.use(IconsPlugin)
I'm using the recommended Versions of
"bootstrap": "^4.5.3",
"bootstrap-vue": "^2.21.2",
"sass": "^1.32.13",
"sass-loader": "^10.2.0"
What could be the problem here?
Solution:
I accidentally imported my custom.scss file into my app.vue additionally
<style>
#import 'assets/custom.scss';
</style>

Is there a tooltip tool that works with NuxtJS?

Is there any tooltip tool that is integrated under NuxtJS? Currently I tried to use the v-tooltip but unfortunately I can't use it. Immediately it crashes.
I created the file in the plugins folder named tooltip.js and attached the following code there:
import Vue from 'vue'
import VTooltip from 'v-tooltip'
Vue.use(VTooltip)
Then in nuxt.config.js in the plugins object I attached this file.
Error when used:
ERROR Failed to compile with 1 errors friendly-errors 11:04:04
ERROR in ./components/Dashboard/Navigation/index.vue?vue&type=template&id=a70e9826&
Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js): friendly-errors 11:04:04
(Emitted value instead of an instance of Error)
Errors compiling template:
tag <button> has no matching end tag.
13 | <div class="user-panel">
14 | <div class="notification">
15 | <button v-tooltip="'You have new messages.'">
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16 | <i class="fas fa-envelope">
17 | <div v-if="notification_active" class="notification-dot"></div>
friendly-errors 11:04:04
# ./components/Dashboard/Navigation/index.vue?vue&type=template&id=a70e9826& 1:0-209 1:0-209
# ./components/Dashboard/Navigation/index.vue
# ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./layouts/dashboard.vue?vue&type=script&lang=js&
# ./layouts/dashboard.vue?vue&type=script&lang=js&
# ./layouts/dashboard.vue
# ./.nuxt/App.js
# ./.nuxt/index.js
# ./.nuxt/client.js
# multi eventsource-polyfill webpack-hot-middleware/client?reload=true&timeout=30000&ansiColors=&overlayStyles=&name=client&path=/__webpack_hmr/client ./.nuxt/client.js
friendly-errors 11:04:04
» Updated components\Dashboard\Navigation\index.vue
For me is ok with create
plugins/tooltip.js
import Vue from "vue"
import { VTooltip, VPopover, VClosePopover } from "v-tooltip"
Vue.directive("tooltip", VTooltip);
Vue.directive("close-popover", VClosePopover)
Vue.component("v-popover", VPopover)
add css https://github.com/Akryum/v-tooltip#style-examples
And use
<input
type="text"
value=""
class="form-control"
v-tooltip="'Test tooltip'"
/>
you can use primevue with nuxt 3 and configure tooltip directive in primevue.js (starter : https://github.com/primefaces/primevue-quickstart-nuxt3/tree/main/plugins)
import Message from "primevue/message";
import Sidebar from "primevue/sidebar";
import BlockUI from "primevue/blockui";
import Tooltip from 'primevue/tooltip';
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.use(PrimeVue, { ripple: true })
nuxtApp.vueApp.use(ToastService)
nuxtApp.vueApp.component('Message', Message)
nuxtApp.vueApp.component('Button', Button)
nuxtApp.vueApp.component('InputText', InputText)
nuxtApp.vueApp.component('InputNumber', InputNumber)
nuxtApp.vueApp.component('Toast', Toast)
nuxtApp.vueApp.component('Dropdown', Dropdown)
nuxtApp.vueApp.component('Sidebar',Sidebar)
nuxtApp.vueApp.component('BlockUI',BlockUI)
// nuxtApp.vueApp.component('Tooltip', Tooltip)
nuxtApp.vueApp.directive('tooltip', Tooltip)
//other components that you need
})
With Nuxt3 you can use Floating Vue
yarn add floating-vue
Create file plugins/floating-vue.ts with below code
Enjoy nice tooltip as component or directive :)
plugins/floating-vue.ts
import FloatingVue from 'floating-vue'
import 'floating-vue/dist/style.css'
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.use(FloatingVue)
})

Components of Vuestrap not working with Vue2

In a single file component in the project created by vue-cli, i want to import some components of vuestrap:
import Vue from 'vue'
import alert from 'vue-strap/src/alert'
import dropdown from 'vue-strap/src/Dropdown'
export default {
name: 'todo',
components: {
alert, dropdown
},
data() {
return {
msg: '...'
}
}
}
If I only import alert, it is working without any problem. However, if I import Input, Dropdown, i get errors inside the vue files of the vuestrap files itself:
ERROR in ./~/vue-loader/lib/template-compiler.js?id=data-v-5f7de981!./~/vue-loader/lib/selector.js?type=template&index=0!./~/vue-strap/src/Dropdown.vue
Vue template syntax error:
v-else used on element <ul> without corresponding v-if.
# ./~/vue-strap/src/Dropdown.vue 9:2-143
# ./~/babel-loader/lib!./src/components/todolist/todolist.js
# ./src/components/ToDo.vue
# ./src/router/index.js
# ./src/main.js
# multi ./build/dev-client ./src/main.js
ERROR in ./~/vue-loader/lib/template-compiler.js?id=data-v-5f7de981!./~/vue-loader/lib/selector.js?type=template&index=0!./~/vue-strap/src/Dropdown.vue
Vue template syntax error:
class="btn btn-{{type}} dropdown-toggle": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div class="{{ val }}">, use <div :class="val">.
# ./~/vue-strap/src/Dropdown.vue 9:2-143
# ./~/babel-loader/lib!./src/components/todolist/todolist.js
# ./src/components/ToDo.vue
# ./src/router/index.js
# ./src/main.js
# multi ./build/dev-client ./src/main.js
For some components the build is completely crashed (e.g. Datepicker).
My question is: is Vuestrap not compatible with Vue2 as they said in the documentation? Or am I missing something?