【问题标题】:Can't update Vuetify project to vuetify 2.0.0-beta5无法将 Vuetify 项目更新为 Vuetify 2.0.0-beta5
【发布时间】:2019-11-16 10:06:08
【问题描述】:

vuetify LTS 更新到vuetify 2.0.0-beta.5 时出现问题。

在一切正常之前,vuetify 样式是从 app.scss 加载的

错误:

[Vue 警告]:观察者“isDark”的 getter 错误:“TypeError:不能 读取未定义的“黑暗”属性”

TypeError: 无法读取未定义的属性 'dark'

[Vue 警告]:渲染错误:“TypeError:无法读取属性‘dark’ 未定义”

我已经卸载了 vuetify,然后安装并更新到像 https://stackoverflow.com/a/49250912 这样的 beta 版本

package.json

{
  "devDependencies": {
    "@fortawesome/fontawesome-free": "^5.9.0",
    "@mdi/font": "^3.7.95",
    "@symfony/webpack-encore": "^0.22.0",
    "axios": "^0.19.0",
    "chart.js": "^2.8.0",
    "less": "^3.9.0",
    "less-loader": "^4.1.0",
    "material-design-icons-iconfont": "^5.0.1",
    "node-sass": "^4.11.0",
    "sass-loader": "^7.1.0",
    "vue": "^2.6.8",
    "vue-loader": "^15.7.0",
    "vue-template-compiler": "^2.6.8",
    "webpack-dev-server": "^3.2.1",
    "webpack-notifier": "^1.6.0"
  },
  "license": "UNLICENSED",
  "private": true,
  "scripts": {
    "dev-server": "encore dev-server --hot --disable-host-check --host 174.28.1.5 --public 174.28.1.5:8080",
    "dev": "encore dev",
    "watch": "encore dev --watch",
    "build": "encore production --progress"
  },
  "dependencies": {
    "apexcharts": "^3.8.1",
    "chart.js": "^2.8.0",
    "core-js": "^3.1.4",
    "vue-apexcharts": "^1.4.0",
    "vue-google-signin-button": "^1.0.4",
    "vue-telegram-login": "^2.1.0",
    "vuetify": "^1.5.14",
    "vuex": "^3.1.1"
  }
}

webpack.config.js

var path = require('path');
var Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('public/build/')
    .setPublicPath('/build')
    .addStyleEntry('styles', './assets/css/app.scss')
    .enableSassLoader()
    .enableVueLoader()
    .addEntry('landing', './assets/js/modules/landing/main.js')
    .addEntry('main', './assets/js/modules/dashboard/main/main.js')
    .addEntry('main-m', './assets/js/modules/dashboard_m/main.js')
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    .cleanupOutputBeforeBuild()
    .enableVersioning(Encore.isProduction())
    .enableSingleRuntimeChunk()
;
main_config = Encore.getWebpackConfig();
main_config.resolve.alias["~"] = path.resolve(__dirname, 'assets/js');
module.exports = main_config;

ma​​in.js

import Vue from 'vue';
import Vuetify from 'vuetify';
import VueApexCharts from 'vue-apexcharts';
import Dashboard from './Dashboard';
import store from './store/index'

Vue.component('current-session', () => import('./DashboardModule'));

Vue.use(Vuetify, {
    iconfont: 'fa'
});
Vue.use(VueApexCharts);

Vue.component('apexchart', VueApexCharts);

require('apexcharts');
require('vue-apexcharts');

new Vue({
    el: '#dashboard-m',
    store,
    components: {Dashboard},
    render: a => a(Dashboard),
});

app.scss

@import "~@fortawesome/fontawesome-free/css/all.min.css";

已经尝试通过添加 vuetify-loader 来修复它,并不是说我做得正确但它仍然无法正常工作,这里是我的更新:

webpack.config.js

const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
// .enableSassLoader() - turned off it
.addLoader({
    test: /\.s(c|a)ss$/,
    use: [
        'style-loader',
        'vue-style-loader',
        'css-loader',
        {
            loader: 'sass-loader',
            options: {
                implementation: require('sass'),
                fiber: require('fibers'),
                indentedSyntax: true, // optional
            }
        }
    ]
})

package.json

中删除node-sass

所以当一个添加了这个

<v-app id="inspire" :dark="false">

我已经用&lt;v-app&gt; 标签解决了我的问题,但是得到了另一个组件不加载默认道具 像这样:

[Vue 警告]:挂载钩子错误:“TypeError:无法读取属性 未定义的‘注册’”

或者这个:

[Vue 警告]:观察者“showOverlay”的 getter 错误:“TypeError: 无法读取未定义的属性“宽度”

【问题讨论】:

    标签: javascript vue.js vuetify.js webpack-encore


    【解决方案1】:

    感谢 jacek(Vuetify 核心团队) 这里是添加 vuetify 到 Vue 的正确方法:

    // v2.0
    import Vue from 'vue'
    import Vuetify from 'vuetify'
    import 'vuetify/dist/vuetify.min.css'
    
    const opts = { ... }
    Vue.use(Vuetify)
    
    new Vue({
      vuetify: new Vuetify(opts)
    }).$mount('#app')
    

    【讨论】:

    • 谢谢你,先生。为我节省了很多时间。下一步是从 vuetify/lib 加载——它在 Vuetify beta 7 中被破坏了。
    • 加载什么? css?
    • @Vixtrime,我猜上述方法在 beta7 中不起作用。示例:stackoverflow.com/q/57019082/4050261
    • @AdarshMadrecha,有趣,更新到 beta.7 后它仍然对我有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2019-11-21
    • 2019-01-03
    • 2018-07-18
    • 2020-09-08
    • 2022-08-11
    相关资源
    最近更新 更多