search

Home  >  Q&A  >  body text

javascript - Webpack custom attribute md-icon-src is not converted when packaging

There is a component in my Vue project

  <md-bottom-bar-item v-for="tab in tabs"
    :id="tab.id"
    md-icon-src="../assets/icon/ic_home_black_48px.svg"
    :md-active='tab.active'>{{ tab.title }}
  </md-bottom-bar-item>

But when npm run build, md-icon-src is not converted into a packaged path.
But check that webpack.base.conf.js supports svg

  {
    test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
    loader: 'url-loader',
    options: {
      limit: 10000,
      name: utils.assetsPath('img/[name].[hash:7].[ext]')
    }
  },

Is this because md-icon-src is a custom attribute? How to solve it.

阿神阿神2827 days ago749

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-18 11:00:30

    You also need to set transformToRequire for vue-loader in webpack, and the md-icon-src attribute of the md-bottom-bar-item element must be converted to require.

    See: http://vue-loader.vuejs.org/e...

    Or attend this lecture: /l/15..., 35% off limited time offer.

    Another idea is to require the svg file in the script to give the component instance data, and then bind the data to md-icon-src.

    reply
    0
  • Cancelreply