美文网首页
vue 引入外部js的变量、常量或方法

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

作者: 奕格 | 来源:发表于2018-12-12 15:25 被阅读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)

             }

        }   

相关文章

网友评论

      本文标题:vue 引入外部js的变量、常量或方法

      本文链接:https://www.haomeiwen.com/subject/rczuhqtx.html