polymer 3.0 uncaught reference error on paper drop-down click

这一生的挚爱 提交于 2019-12-03 16:31:03

You need to install the neon-animation element. Do this:

npm install --save @polymer/neon-animation

This will add the neon-animation dependency in your package.json and install it as well. Add the web-animations-js polyfill:

npm install --save web-animations-js

Once you are done installing these two. In the view which is responsible for the dropdown. Add the following code:

 import {NeonAnimationRunnerBehavior} from '@polymer/neon-animation/neon-animation-runner-behavior.js';

you will have to use the mixinbehavior so add this as an import:

 import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';

Now say the name of the class is MyView1 where you are rendering this dropdown do this:

class MyView1 extends mixinBehaviors([NeonAnimationRunnerBehavior], PolymerElement) {

Now we need to add the polyfill web-animations-js to the index.html just after the web-components-loader:

<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="node_modules/web-animations-js/web-animations-next.min.js"></script>

This will definitely work!

The Web Animations polyfill resolves the error you're seeing. Install it from npm:

npm i -S web-animations-js

Then, import it before using the paper-dropdown-menu, like this:

Firefox:

import 'web-animations-js/web-animations-next-lite.min.js';

demo 1

Chrome

<script src="./node_modules/web-animations-js/web-animations-next-lite.min.js"></script>

Note: Unfortunately in Chrome, the web-animations-next-lite.min.js file must be imported with a <script> tag (e.g., in index.html). This works in both Firefox and Chrome.

demo 2

in package.json "dependencies"

   "web-animations-js": "^2.3.1" 

in polymer.json "extraDependencies"

   "node_modules/web-animations-js/*.js"

in index.html AFTER webcomponents-loader script

   <script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
   <script src="node_modules/web-animations-js/web-animations-next.min.js"></script>

importing any of the web-animation-js polyfill versions as javascript modules directly in my element and building with Polymer CLI produced the topic error. Loading the web-animations-next.min.js polyfill version synchronously in index.html after webcomponents loader script fixed error for me

Neon-animations are oficially deprecated, anyhow you can still download from https://www.npmjs.com/package/@polymer/neon-animation

To import'em in your polymer3 project from npm:

npm install --save @polymer/neon-animation

With regards to the previous answer by MKant, if you have an ASP.net site, you will need to add the last two script tags for the polyfills into your cshtml file or whichever file is calling your Polymer element. If you add them into your module template code, it will not work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!