0

I tried to use vue-cli to create my vue project and using semantic ui. Please review my steps:

  1. vue init webpack test
  2. npm install
  3. npm install semantic-ui --save

then my project structure looks as below.

enter image description here

my webpack.base.config

'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

module.exports = {
  entry: {
    app: './src/main.js'
  },
  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
    }
  },
  module: {
    rules: [
      {
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        enforce: 'pre',
        include: [resolve('src'), resolve('test')],
        options: {
          formatter: require('eslint-friendly-formatter')
        }
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test')]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('media/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }
    ]
  }
}

my main.js file

import Vue from 'vue'
import App from './App'
import router from './router'
import '../semantic/dist/semantic.min.css'
import '../semantic/dist/semantic.min.js'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})

in my vue file, I add some semantic-ui elements, then run the command 'npm run dev', I got the exception

Uncaught ReferenceError: jQuery is not defined

Anyone can help?

Allen4Tech
  • 2,094
  • 3
  • 26
  • 66
  • You have sintax errors with these `import '../semantic/dist/semantic.min.css'`, `import '../semantic/dist/semantic.min.js'` – ricardoorellana Oct 13 '17 at 06:10
  • @RicardoOrellana so what should I do? – Allen4Tech Oct 13 '17 at 06:12
  • My bad @Allen4Tech the import sintax is correct. It seems that semantic-ui requires you integrates jQuery in your project, maybe this answer can help you https://stackoverflow.com/questions/36676215/using-vue-js-with-semantic-ui – ricardoorellana Oct 13 '17 at 06:19
  • I tried, the exception disappear, but it looks semantic's js file doesn't work. I can see the element's style as same as in semantic-ui doc, but when I try to operate the element, there's no effect. For example, there's a menu in my page, when I click other inactive item, the item should be active, but nothing happens – Allen4Tech Oct 13 '17 at 06:45
  • Try a fully ported version of semantic from jQuery to vuejs. Like https://semantic-ui-vue.github.io/#/ or https://github.com/almino/semantic-ui-vue2 – skribe Oct 13 '17 at 07:41
  • 2
    It's sort of pain and not good idea to use native semantic ui, because It relies on jQuery.You can use jQuery in VueJS but It's not really reccommended because you will touch DOM directly.There is already posted Semantic UI version that use Vue for Javascript instead of jQ, so my suggestion is go with that. – Belmin Bedak Oct 13 '17 at 07:55

0 Answers0