I'm new to Buefy and Vue.
I'm using the following libraries through CDN: bulma0.9.3 vue2.6.14 buefy0.9.13 fontawesome5.15.4
Two files index.html and index.js are being used.
I'm tried to set the defaultIconPack to fontawesome globally by following the instructions given at Constructor options - Buefy documentation. But the icons in index.html defaults to mdi and not to fontawesome.
index.js
Vue.use(Buefy, {
defaultIconPack: 'fas'
});
let vm = new Vue({
el: "#app",
delimiters: ["[[", "]]"],
data: {
data: [],
columns: []
},
mounted: function () {
document.getElementById('main').classList.add('is-active');
},
methods: {},
computed: {}
})
Please advise.
Try using this.$buefy.config, like this:
mounted:function () {
this.$buefy.config.setOptions({defaultIconPack: 'fas'});
document.getElementById('main').classList.add('is-active');
},
Related
If you open any CodeSandbox Vue template or vue-cli 3 template, you can notice this code in main.js
Method 1
new Vue({
render: (h) => h(App),
}).$mount("#app");
I'm a little bit confused about this code, why not just
Method 2
new Vue(App).$mount("#app");
Is there any benefit of writing Method 1?
Yes, there is a benefit - when you use the options object you can also add Vue-Router, Vuex, define some data, computed properties, watchers, methods and even some lifecycle hooks. For example:
new Vue({
data:
{
currentUser: null,
lastError: null,
showLoadingSpinner: false,
},
computed:
{
baseURL()
{
return process.env.BASE_URL;
}
},
created()
{
this.$on('logout', this.logout);
},
beforeDestroy()
{
this.$off('logout', this.logout);
},
router: myRouter,
store: myStore,
render: h => h(App),
}).$mount('#app');
When i include css,scss files in my entry app file, system adds these css file contents as inline css. But i want them to compiled in one file and import in page automatically like other js files instead of inline css.
Before: page content is like this https://prnt.sc/sj2wde.
After: Something like this
<link rel="stylesheet" href="/assets/css/0.styles.7462b628.css">
// Include scss file
import './assets/index.scss';
export function createApp() {
const router = createRouter();
const store = createStore();
sync(store, router);
const app = new Vue({
router,
store,
render: (h) => h(App),
});
return { app, router, store };
}
I tried to use mini-css-extract-plugin plugin but it works only for standalone vuejs components.
//webpack module rule
{
test: /\.css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[local]_[hash:base64:8]',
},
},
},
],
}
When I use Vue in an HTML file like below, it works fine.
<body>
<div id="app">
<!-- something in here -->
</div>
<script>
new Vue({
el: "#app",
data: function() {
}
//and so on ....
})
</script>
</body>
But When I use webpack to build it. The output js file which I put in HTML header does not parse the HTML correctly. And seems Vue.js is not working.
Here are my webpack config file and entry js file.
/**
* webpack.config.js
*/
const path = require('path');
module.exports = {
entry: './src/index.js',
output:{
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module:{
rules:[
{
test: /\.css$/,
use:[
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif|ico)$/,
use:[
'file-loader'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use:[
'file-loader'
]
}
]
}
}
/**
* index.js (the entry js file)
*/
import axios from "axios";
import Vue from "vue";
var baseUrl = "/activity/gqzq/AjaxGetList";
var vm = new Vue({
el: "#app",
data: function() {},
//......
})
My question is, Why the output file is not working? And how to make it right?
Just use the proper official tools, all the Webpack is configured for you.
https://cli.vuejs.org/
I am new to Vue and I've been toying around with a basic component and trying to get some interactivity to work. However, when attempting to implement some methods, I find that nothing actually happens. My code looks like this:
var testComponent = Vue.component('testComponent', {
data: function () {},
props: [ 'maps' ],
methods: {
filt: function() {
alert("Useful alert");
}
},
template: "<div><button class='btn-primary' #click='filt'>Filter</button></div>"
});
var vm = new Vue({
el: '#app',
data: {},
methods: {},
computed: {},
components: {
TestComponent: testComponent
},
ready: function () {}
});
And my HTML essentially contains only this:
<test-component></test-component>
I would like to call the testComponent's filt method (which will later hopefully become a working filter method for the maps prop), but the button gives no alert on pressing it.
I've tried a few variations like v-on:click, but to no avail.
Any help would be greatly appreciated!
var app = new Vue({
el: '#app',
data: {
positions: []
},
created() {
axios.get('/config').then(function(response) {
this.$set(this.positions, "positions", response.data[0].dragedPositions);
});
console.log(this.positions.positions);
}
});
I have configs for my app in database and I want to use them inside of Vue instance (here are positions of my elements). But when im getting "this.positions.positions" Im getting empty string.. How can I do that?
Sounds like you want to load config first and bootstrap application after that. Use propsData for this:
axios.get('/config').then(function(response) {
new Vue({
el: '#app',
props: ['positions'],
propsData: {
positions: response.data[0].dragedPositions
},
created() {
console.log(this.positions);
}
});
});
I even created little demo :)
const axios = {get () {
return Promise.resolve({data: [{dragedPositions: [1,2]}]})
}}
axios.get("/config").then(function(response) {
new Vue({
el: "#app",
props: ['positions'],
propsData: {
positions: response.data[0].dragedPositions
},
created() {
console.log('created hook', this.positions);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
<pre id="app">positions = {{ positions }}</pre>
Can you try this trick? See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
var self = this;
axios.get('/config').then(function(response) {
self.$set(self.positions, "positions", response.data[0].dragedPositions);
});
By the way, It seems that you should initialize your positions as an object instead of an array.