Bootstrap Table not working with vue and laravel - laravel

trying to add BootstrapTable to some component but it give me
TypeError: Cannot call a class as a function
when calling the
<BootstrapTable ref="table"/>
i'm using laravel also my app.js
require('./bootstrap');
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-table/dist/bootstrap-table.min.css'
import jQuery from 'jquery'
window.$ = jQuery
//import Vue from 'vue'
import 'bootstrap'
import 'bootstrap-table/dist/bootstrap-table.js'
import BootstrapTable from 'bootstrap-table/dist/bootstrap-table-vue.esm.js'
window.Vue = require('vue');
import VueRouter from 'vue-router';
import { routes } from './routes';
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
routes
});
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('dashboard', require('./components/Dashboard').default);
Vue.component('BootstrapTable', BootstrapTable)
const app = new Vue({
router
}).$mount('#app');
and component vue
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Example Dashboard</div>
<div class="card-body">
<BootstrapTable :columns="columns" :data="data" :options="options"></BootstrapTable>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import BootstrapTable from "bootstrap-table";
export default {
components: {
BootstrapTable: BootstrapTable
},
data() {
return {
columns: [
{
title: "Item ID",
field: "id"
},
{
field: "name",
title: "Item Name"
},
{
field: "price",
title: "Item Price"
}
],
data: [
{
id: 1,
name: "Item 1",
price: "$1"
},
{
id: 2,
name: "Item 2",
price: "$2"
},
{
id: 3,
name: "Item 3",
price: "$3"
},
{
id: 4,
name: "Item 4",
price: "$4"
},
{
id: 5,
name: "Item 5",
price: "$5"
}
],
options: {
search: true,
showColumns: true
}
};
},
mounted() {
console.log("Dashboard mounted.");
}
};
</script>
please any help ? many thanks on advance.

Related

Vue Component in Laravel Blade won't render unless renamed

I have made a Vue component built in a Laravel application for rendering a series of address fields:
<template>
<div>
<label for="address_line_1">Address line 1</label>
<input type="text" id="address_line_1" name="address_line_1" placeholder="Address line 1" :value="addressLine1" #input="setAddressLine1($event.target.value)" :class="{ 'is-invalid': errors.address_line_1 }" required>
</div>
. . .
</template>
<script>
import { mapActions } from "vuex";
export default {
props: {
addressLine1: { type: String },
addressLine2: { type: String },
city: { type: String },
province: { type: String },
postalCode: { type: String },
country: { type: String },
module: { type: String } ,
initErrors: { type: Object },
},
data() {
return {
errors: this.initErrors || {}
}
},
methods: {
...mapActions('collection', ['setAddressLine1', 'setAddressLine2', 'setCity', 'setProvince', 'setPostalCode', 'setCountry']),
},
}
</script>
The file is in a components directory names Address.vue, it's includes in my application templates as:
<address
module="collection"
address-line1="{{ old('address_line_1', session('collection.address_line_1')) }}"
address-line2="{{ old('address_line_2', session('collection.address_line_2')) }}"
city="{{ old('city', session('collection.city')) }}"
province="{{ old('city', session('collection.city')) }}"
postal-code="{{ old('postal_code', session('collection.postal_code')) }}"
country="{{ old('country', session('collection.country')) }}"
:init-errors='#json($errors->messages(), JSON_FORCE_OBJECT)'
></address>
And included in app.js (simplified here)
import Vue from 'vue'
import Address from './components/Address.vue'
const app = new Vue({
el: '#app',
components: { Address },
store: store,
});
require('./bootstrap');
The component does not render on the page at all. There are no JavaScript errors. Other included components are working fine.
However, I have found that if rename all references to the component to e.g. AddressX and then it renders and functions as expected.
Any clues as to why this might be?

How can add a button count on my component VueJS

i starting learn VueJS and i can't add my button count on my component, i'm work with laravel !
My app.js:
window.Vue = require('vue');
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import Home from './components/HomeComponent.vue'
import Categorie from './components/CategorieComponent.vue'
let routes = [
{
path: '/',
component: Home
},
];
const app = new Vue({
mode: 'history',
el: '#app',
router: router,
data: {
message: 'Hello Vue'
}
});
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">Vous m\'avez cliqué {{ count }} fois.</button>'
});
My HomeComponent.vue:
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card-body">
<h1 class="card-tite">Bienvenue sur mon site</h1>
<button-counter></button-counter>
</div>
</div>
</div>
</div>
</template>
I add a div "app" and on this i add a <router-view><router-view> :)
My console VueJS say me :
Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
As told in the error message, you have to register your component, before using it. Have a look on this article to read more about it.
In your example, you have to move the Vue.component('button-counter', { ... }) part in from of your app initialize. It is just another component (similar to your HomeComponent) that is defined.
Change your app.js like this:
window.Vue = require('vue');
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import Home from './components/HomeComponent.vue'
import Categorie from './components/CategorieComponent.vue'
let routes = [
{
path: '/',
component: Home
},
];
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">Vous m\'avez cliqué {{ count }} fois.</button>'
});
const app = new Vue({
mode: 'history',
el: '#app',
router: router,
data: {
message: 'Hello Vue'
}
});
... and your example should work properly.
Have a look at this running fiddle with your example.

Errors with vee-validate custome rule

In #vue/cli 4.1.1 app I use v-money and vee-validate and I see that required rule does not work for
v-money , as it always has “0” value. So I make custom validation as it is written here
http://vee-validate.logaretm.com/v2/guide/custom-rules.html#using-the-custom-rule
Inserting this exam[ple in test page I got warnings in console :
WARNING Compiled with 2 warnings 7:45:56 AM
warning in ./src/views/Test.vue?vue&type=script&lang=js&
"export 'Validator' was not found in 'vee-validate'
warning in ./src/views/Test.vue?vue&type=script&lang=js&
"export 'Validator' was not found in 'vee-validate'
App running at:
- Local: http://localhost:8080/
- Network: unavailable
and in browser I see error :
vue-router.esm.js?8c4f:2113 TypeError: Cannot read property 'extend' of undefined
at eval (Test.vue?f246:87)
at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/Test.vue?vue&type=script&lang=js& (4.js:11)
at __webpack_require__ (app.js:790)
at fn (app.js:151)
My test component :
<template>
<div class="frontend_item_container">
<ValidationObserver
ref="pageObserverForm"
v-slot="{handleSubmit}"
>
<b-form #submit.prevent="handleSubmit(onSubmit)">
<b-card-header>
<h3 class="row_content_left_aligned p-2" v-show="is_page_loaded">
<i :class="'info_link '+getHeaderIcon('page')"></i>{{ getHeaderTitle }}
</h3>
<div v-show="!is_page_loaded">
<h3>
<b-spinner variant="success" label="Page loading"></b-spinner> Page loading...
</h3>
</div>
</b-card-header>
<b-card-body v-show="is_page_loaded">
<b-row class="editor_row">
<b-col md="4">
<label for="editable_ad_price" class="pt-2 ">
Price<span class="required"> * </span>:
</label>
</b-col>
<b-col md="8">
price::{{ price}}
<ValidationProvider
name="editable_ad_price"
rules="required|truthy"
v-slot="{ errors }"
>
<money
v-model="price"
v-bind="moneyConfig"
name="editable_ad_price"
id="editable_ad_price"
class="form-control text-right"
placeholder="Enter price"
>
</money>
<p class="validation_error">{{ clearErrorMessage(errors[0]) }}</p>
</ValidationProvider>
</b-col>
</b-row>
</b-card-body>
<b-card-footer class="buttons_container" v-show="is_page_loaded">
<b-button size="md" #click.prevent="$router.push('/admin/pages')" class="m-3">
<i :class="'a_link '+getHeaderIcon('cancel')"></i>Cancel
</b-button>
<b-button type="submit" size="md" variant="success" class="m-3">
<i :class="'action_link '+getHeaderIcon('save')"></i>{{ submit_label }}
</b-button>
</b-card-footer>
</b-form>
</ValidationObserver>
</div>
</template>
<script>
import appMixin from '#/appMixin';
import Vue from 'vue'
import money from 'v-money'
Vue.use(money, {precision: 4})
import {settingsLocalizeMessages} from '#/app.settings.js'
import {ValidationObserver, ValidationProvider, extend} from 'vee-validate'
import * as rules from 'vee-validate/dist/rules';
Object.keys(rules).forEach(rule => {
extend(rule, rules[rule]);
});
import { Validator } from 'vee-validate';
Validator.extend('truthy', {
getMessage: field => 'The ' + field + ' value is not truthy.',
validate: value => !! value
});
let instance = new Validator({ trueField: 'truthy' });
instance.extend('falsy', (value) => ! value);
instance.attach({
name: 'falseField',
rules: 'falsy'
});
import {localize} from 'vee-validate';
localize({
en: settingsLocalizeMessages['en']
});
export default {
data() {
return {
apiUrl: process.env.VUE_APP_API_URL,
price: 12,
moneyConfig: {
decimal: ',',
thousands: '.',
prefix: '$',
suffix: '',
precision: 2,
masked: false
},
is_page_loaded: false,
}
}, // data() {
name: 'testPage',
mixins: [appMixin],
components: {
ValidationObserver, ValidationProvider
},
mounted() {
}, // mounted() {
created() {
}, // created() {
beforeDestroy() {
},
methods: {
}, // methods: {
computed: {
getHeaderTitle: function () {
return 'Test'
},
}, //computed: {
}
</script>
Why error and how to fix it ?
"bootstrap-vue": "^2.3.0",
"v-money": "^0.8.1",
"vee-validate": "^3.2.1",
"vue": "^2.6.11",
Thanks!
You are using the old documentation for vee-validate. In version 3 you have to do:
import { extend } from 'vee-validate';
Also check out the 3.x docs here: https://logaretm.github.io/vee-validate/guide/basics.html#adding-rules

Implement vue draggable in a table. Laravel

I'm trying to create a survey with the option to order the questions that are displayed in a table when creating the survey.
I'm using vue draggable and the example works but I don't know how to use this with a table and still get the rows to be draggable
Example
<draggable v-model="section" #start="drag=true" #end="drag=false">
<div v-for="section in surveySections" :key="section.id">{{section.title}}</div
</draggable>
This is the table
<el-table
:data="form.question_id"
border>
<draggable v-model="surveyQuestions" #start="drag=true" #end="drag=false">
<el-table-column prop="title" label="Pregunta"></el-table-column>
<el-col :xs="5">
<el-table-column fixed="right" label="Operaciones">
<template slot-scope="scope">
<el-button
#click.native.prevent="deleteRow(scope.$index, form.question_id)"
type="text" size="small">
<span class="icon-create">Eliminar</span>
<i class="el-icon-delete-solid"></i>
</el-button>
</template>
</el-table-column>
</el-col>
</draggable>
</el-table>
How can I get this to work?
I must have 50 reputation to comment!
SO.
you can see elementUI Table组件实现拖拽效果
e.g
npm install sortablejs --save
// Element table must specify row-key . Otherwise, the order will be wrong
import Sortable from 'sortablejs'
<template>
<div style="width:800px">
<el-table :data="tableData"
border
row-key="id"
align="left">
<el-table-column v-for="(item, index) in col"
:key="`col_${index}`"
:prop="dropCol[index].prop"
:label="item.label">
</el-table-column>
</el-table>
<pre style="text-align: left">
{{dropCol}}
</pre>
<hr>
<pre style="text-align: left">
{{tableData}}
</pre>
</div>
</template>
<script>
import Sortable from 'sortablejs'
export default {
data() {
return {
col: [
{
label: '日期',
prop: 'date'
},
{
label: '姓名',
prop: 'name'
},
{
label: '地址',
prop: 'address'
}
],
dropCol: [
{
label: '日期',
prop: 'date'
},
{
label: '姓名',
prop: 'name'
},
{
label: '地址',
prop: 'address'
}
],
tableData: [
{
id: '1',
date: '2016-05-02',
name: '王小虎1',
address: '上海市普陀区金沙江路 100 弄'
},
{
id: '2',
date: '2016-05-04',
name: '王小虎2',
address: '上海市普陀区金沙江路 200 弄'
},
{
id: '3',
date: '2016-05-01',
name: '王小虎3',
address: '上海市普陀区金沙江路 300 弄'
},
{
id: '4',
date: '2016-05-03',
name: '王小虎4',
address: '上海市普陀区金沙江路 400 弄'
}
]
}
},
mounted() {
this.rowDrop()
this.columnDrop()
},
methods: {
//行拖拽
rowDrop() {
const tbody = document.querySelector('.el-table__body-wrapper tbody')
const _this = this
Sortable.create(tbody, {
onEnd({ newIndex, oldIndex }) {
const currRow = _this.tableData.splice(oldIndex, 1)[0]
_this.tableData.splice(newIndex, 0, currRow)
}
})
},
//列拖拽
columnDrop() {
const wrapperTr = document.querySelector('.el-table__header-wrapper tr')
this.sortable = Sortable.create(wrapperTr, {
animation: 180,
delay: 0,
onEnd: evt => {
const oldItem = this.dropCol[evt.oldIndex]
this.dropCol.splice(evt.oldIndex, 1)
this.dropCol.splice(evt.newIndex, 0, oldItem)
}
})
}
}
}
</script>
<style scoped>
</style>
element ui table Sortable.js

Element type is invalid: expected a string or a class/function but got: object..

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
So Im using react js with spring boot in my application. I have configured webpack successfuly (I think) but the problem I have is after the HTML page is loaded it doesnt render anything in the "div" tag. :(
App.js
import {React} from 'react';
import {ReactDOM} from 'react-dom';
const client = require('./client');
//import css from "./App.css";
import {NavBar} from './navbar';
import {Home} from './home';
//const index = require('/alpha/src/main/resources/templates/index.html');
const heroImageStyling = {
height: 200,
width: 200
};
class App extends React.Component {
state = {
products: [
{ id: 1, value: 0, name: "Item 1" },
{ id: 2, value: 0, name: "Item 2" },
{ id: 3, value: 0, name: "Item 3" },
{ id: 4, value: 0, name: "Item 3" },
{ id: 5, value: 0, name: "Item 3" },
{ id: 6, value: 0, name: "Item 4" },
{ id: 7, value: 0, name: "Item 4" },
{ id: 8, value: 0, name: "Item 5" }
]
};
constructor(props) {
super(props);
this.state = {products: []};
}
componentDidMount() {
client({ method: "GET", path: "/" }).done(response => {
this.setState({ products: response.entity._embedded.products });
});
}
handleDelete = id => {
console.log("event handled", id);
};
handleNavBarCartIncrement = product => {
const products = [...this.state.products];
const index = products.indexOf(product);
products[index] = { ...product };
products[index].value++;
this.setState({ products });
console.log(product);
};
render() {
return (
<React.Fragment>
<NavBar
cartItems={this.state.products.filter(c => c.value > 0).length}
/>
<main className="container">
<Home
products={this.state.products}
onIncrement={this.handleNavBarCartIncrement}
onDelete={this.handleDelete}
/>
</main>
</React.Fragment>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('react')
)
index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<meta charset="UTF-8"/>
<title>ReactJS + Spring Data REST</title>
<link rel="stylesheet" href="/main.css" />
</head>
<body>
<div id="react"></div>
<script src="/built/bundle.js"></script>
</body>
</html>
My index.html used to get the react component but did not display anything other than an tag without anything. But not it doesnt do that either. Now it doesnt retrieve anything but instead it gets the following errors.
You must import React, ReactDom and your classes without curly braces.
If you use export default to export your file, you don't need to put curly braces, if you use only export, then you must use {}
Another thing is that if you don't want to do configure webpack and bable by yourself, you can use create-react-app command to create a new react project and all will be set for you.
The command is: npx create-react-app myApp

Resources