vue 引入外部js的变量、常量或方法

2018-12-12  本文已影响0人  奕格

1,变量引用

    外部js:

        var s = "变量数据";

        export default{

            customData:function () {

                return s;

            }

        }

.vue实例文件

    import SM from "../../static/js/networkRequest"

        export default {

            data () {

                return{

                    newData:SM.customData()

                }

            }

        }   

2,方法调用

    外部js:

        function test(){

            console.log("tttttttttttttttttttt::::")

        }

        export {

            test

        }

    .vue实例文件

        import  { test} from "../../static/js/mathUtils"

        created(){

            this.test2();

        },

        methods: {

            test2(){

                test()

            }

        }

3,变量引用

      外部js:

        const S="dd"

        export {

            accMul,

            S

        }

     .vue实例文件

        import  { accMul,S } from  "../../static/js/mathUtils"

        export default {

            data () {

                return{

                    str:S

                }

            },

             created(){

              console.log("=====================::::" +accMul(2,4))

               console.log("=====================::::" +this.str)

             }

        }   

上一篇 下一篇

猜你喜欢

热点阅读